home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / clx.lha / clx / doc.l < prev    next >
Lisp/Scheme  |  1988-09-12  |  136KB  |  3,681 lines

  1. ;;; -*- Mode: LISP; Syntax: Common-lisp; Package: (XLIB (CL)); Base: 10; Lowercase: Yes -*-
  2.  
  3. ;;; Copyright 1987, 1988 Massachusetts Institute of Technology, and
  4. ;;;             Texas Instruments Incorporated
  5.  
  6. ;;; Permission to use, copy, modify, and distribute this document for any purpose
  7. ;;; and without fee is hereby granted, provided that the above copyright notice
  8. ;;; appear in all copies and that both that copyright notice and this permission
  9. ;;; notice are retained, and that the name of M.I.T. not be used in advertising or
  10. ;;; publicity pertaining to this document without specific, written prior
  11. ;;; permission.  M.I.T. makes no representations about the suitability of this
  12. ;;; document or the protocol defined in this document for any purpose.  It is
  13. ;;; provided "as is" without express or implied warranty.
  14.  
  15. ;;; Texas Instruments Incorporated provides this document "as is" without
  16. ;;; express or implied warranty.
  17.  
  18. ;; Version 4
  19.  
  20. ;; This is considered a somewhat changeable interface.  Discussion of better
  21. ;; integration with CLOS, support for user-specified subclassess of basic
  22. ;; objects, and the additional functionality to match the C Xlib is still in
  23. ;; progress.
  24.  
  25. ;; Primary Interface Author:
  26. ;;    Robert W. Scheifler
  27. ;;    MIT Laboratory for Computer Science
  28. ;;    545 Technology Square, Room 418
  29. ;;    Cambridge, MA 02139
  30. ;;    rws@zermatt.lcs.mit.edu
  31.  
  32. ;; Design Contributors:
  33. ;;    Dan Cerys, Texas Instruments
  34. ;;    Scott Fahlman, CMU
  35. ;;    Kerry Kimbrough, Texas Instruments
  36. ;;    Chris Lindblad, MIT
  37. ;;    Rob MacLachlan, CMU
  38. ;;    Mike McMahon, Symbolics
  39. ;;    David Moon, Symbolics
  40. ;;    LaMott Oren, Texas Instruments
  41. ;;    Daniel Weinreb, Symbolics
  42. ;;    John Wroclawski, MIT
  43. ;;    Richard Zippel, Symbolics
  44.  
  45. ;; CLX Extensions
  46. ;; Adds some of the functionality provided by the C XLIB library.
  47. ;;
  48. ;; Primary Author
  49. ;;    LaMott G. Oren
  50. ;;    Texas Instruments
  51. ;; 
  52. ;; Design Contributors:
  53. ;;    Robert W. Scheifler, MIT
  54.  
  55.  
  56. ;; Note: all of the following is in the package XLIB.
  57.  
  58. ;; Note: various perversions of the CL type system are used below.
  59. ;; Examples: (list elt-type) (sequence elt-type)
  60.  
  61. (proclaim '(declaration arglist values))
  62.  
  63. ;; Note: if you have read the Version 11 protocol document or C Xlib manual, most of
  64. ;; the relationships should be fairly obvious.  We have no intention of writing yet
  65. ;; another moby document for this interface.
  66.  
  67. (deftype card32 () '(unsigned-byte 32))
  68.  
  69. (deftype card29 () '(unsigned-byte 29))
  70.  
  71. (deftype int32 () '(signed-byte 32))
  72.  
  73. (deftype card16 () '(unsigned-byte 16))
  74.  
  75. (deftype int16 () '(signed-byte 16))
  76.  
  77. (deftype card8 () '(unsigned-byte 8))
  78.  
  79. (deftype int8 () '(signed-byte 8))
  80.  
  81. (deftype mask32 () 'card32)
  82.  
  83. (deftype mask16 () 'card16)
  84.  
  85. (deftype resource-id () 'card29)
  86.  
  87. ;; Types employed: display, window, pixmap, cursor, font, gcontext, colormap, color.
  88. ;; These types are defined solely by a functional interface; we do not specify
  89. ;; whether they are implemented as structures or flavors or ...  Although functions
  90. ;; below are written using DEFUN, this is not an implementation requirement (although
  91. ;; it is a requirement that they be functions as opposed to macros or special forms).
  92. ;; It is unclear whether with-slots in the Common Lisp Object System must work on
  93. ;; them.
  94.  
  95. ;; Windows, pixmaps, cursors, fonts, gcontexts, and colormaps are all represented as
  96. ;; compound objects, rather than as integer resource-ids.  This allows applications
  97. ;; to deal with multiple displays without having an explicit display argument in the
  98. ;; most common functions.  Every function uses the display object indicated by the
  99. ;; first argument that is or contains a display; it is an error if arguments contain
  100. ;; different displays, and predictable results are not guaranteed.
  101.  
  102. ;; Each of window, pixmap, drawable, cursor, font, gcontext, and colormap have the
  103. ;; following five functions:
  104.  
  105. (defun make-<mumble> (display resource-id)
  106.   ;; This function should almost never be called by applications, except in handling
  107.   ;; events.  To minimize consing in some implementations, this may use a cache in
  108.   ;; the display.  Make-gcontext creates with :cache-p nil.
  109.   (declare (type display display)
  110.        (type resource-id resource-id)
  111.        (values <mumble>)))
  112.  
  113. (defun <mumble>-display (<mumble>)
  114.   (declare (type <mumble> <mumble>)
  115.        (values display)))
  116.  
  117. (defun <mumble>-id (<mumble>)
  118.   (declare (type <mumble> <mumble>)
  119.        (values resource-id)))
  120.  
  121. (defun <mumble>-equal (<mumble>-1 <mumble>-2)
  122.   (declare (type <mumble> <mumble>-1 <mumble>-2)))
  123.  
  124. (defun <mumble>-p (<mumble>)
  125.   (declare (type <mumble> <mumble>)
  126.        (values boolean)))
  127.  
  128. ;; The following functions are provided by color objects:
  129.  
  130. ;; The intention is that IHS and YIQ and CYM interfaces will also exist.  Note that
  131. ;; we are explicitly using a different spectrum representation than what is actually
  132. ;; transmitted in the protocol.
  133.  
  134. (deftype rgb-val () '(float 0.0 1.0))
  135.  
  136. (defun make-color (&key red green blue &allow-other-keys)    ; for expansion
  137.   (declare (type rgb-val red green blue)
  138.        (values color)))
  139.  
  140. (defun color-rgb (color)
  141.   (declare (type color color)
  142.        (values red green blue)))
  143.  
  144. (defun color-red (color)
  145.   ;; setf'able
  146.   (declare (type color color)
  147.        (values rgb-val)))
  148.  
  149. (defun color-green (color)
  150.   ;; setf'able
  151.   (declare (type color color)
  152.        (values rgb-val)))
  153.  
  154. (defun color-blue (color)
  155.   ;; setf'able
  156.   (declare (type color color)
  157.        (values rgb-val)))
  158.  
  159. (deftype drawable () '(or window pixmap))
  160.  
  161. ;; Atoms are accepted as strings or symbols, and are always returned as keywords.
  162. ;; Protocol-level integer atom ids are hidden, using a cache in the display object.
  163.  
  164. (deftype xatom () '(or string symbol))
  165.  
  166. (deftype stringable () '(or string symbol))
  167.  
  168. (deftype fontable () '(or stringable font))
  169.  
  170. ;; Nil stands for CurrentTime.
  171.  
  172. (deftype timestamp () '(or null card32))
  173.  
  174. (deftype bit-gravity () '(member :forget :static :north-west :north :north-east
  175.                  :west :center :east :south-west :south :south-east))
  176.  
  177. (deftype win-gravity () '(member :unmap :static :north-west :north :north-east
  178.                  :west :center :east :south-west :south :south-east))
  179.  
  180. (deftype grab-status ()
  181.   '(member :success :already-grabbed :frozen :invalid-time :not-viewable))
  182.  
  183. (deftype boolean () '(or null (not null)))
  184.  
  185. (deftype pixel () '(unsigned-byte 32))
  186. (deftype image-depth () '(integer 0 32))
  187.  
  188. (deftype keysym () 'card32)
  189.  
  190. (deftype array-index () `(integer 0 ,array-dimension-limit))
  191.  
  192. ;; An association list.
  193.  
  194. (deftype alist (key-type-and-name datum-type-and-name) 'list)
  195.  
  196. ;; A sequence, containing zero or more repetitions of the given elements,
  197. ;; with the elements expressed as (type name).
  198.  
  199. (deftype repeat-seq (&rest elts) 'sequence)
  200.  
  201. (deftype point-seq () '(repeat-seq (int16 x) (int16 y)))
  202.  
  203. (deftype seg-seq () '(repeat-seq (int16 x1) (int16 y1) (int16 x2) (int16 y2)))
  204.  
  205. (deftype rect-seq () '(repeat-seq (int16 x) (int16 y) (card16 width) (card16 height)))
  206.  
  207. ;; Note that we are explicitly using a different angle representation than what
  208. ;; is actually transmitted in the protocol.
  209.  
  210. (deftype angle () `(number ,(* -2 pi) ,(* 2 pi)))
  211.  
  212. (deftype arc-seq () '(repeat-seq (int16 x) (int16 y) (card16 width) (card16 height)
  213.                  (angle angle1) (angle angle2)))
  214.  
  215. (deftype event-mask-class ()
  216.   '(member :key-press :key-release :owner-grab-button :button-press :button-release
  217.        :enter-window :leave-window :pointer-motion :pointer-motion-hint
  218.        :button-1-motion :button-2-motion :button-3-motion :button-4-motion
  219.        :button-5-motion :button-motion :exposure :visibility-change
  220.        :structure-notify :resize-redirect :substructure-notify :substructure-redirect
  221.        :focus-change :property-change :colormap-change :keymap-state))
  222.  
  223. (deftype event-mask ()
  224.   '(or mask32 (list event-mask-class)))
  225.  
  226. (deftype pointer-event-mask-class ()
  227.   '(member :button-press :button-release
  228.        :enter-window :leave-window :pointer-motion :pointer-motion-hint
  229.        :button-1-motion :button-2-motion :button-3-motion :button-4-motion
  230.        :button-5-motion :button-motion :keymap-state))
  231.  
  232. (deftype pointer-event-mask ()
  233.   '(or mask32 (list pointer-event-mask-class)))
  234.  
  235. (deftype device-event-mask-class ()
  236.   '(member :key-press :key-release :button-press :button-release :pointer-motion
  237.        :button-1-motion :button-2-motion :button-3-motion :button-4-motion
  238.        :button-5-motion :button-motion))
  239.  
  240. (deftype device-event-mask ()
  241.   '(or mask32 (list device-event-mask-class)))
  242.  
  243. (deftype modifier-key ()
  244.   '(member :shift :lock :control :mod-1 :mod-2 :mod-3 :mod-4 :mod-5))
  245.  
  246. (deftype modifier-mask ()
  247.   '(or (member :any) mask16 (list modifier-key)))
  248.  
  249. (deftype state-mask-key ()
  250.   '(or modifier-key (member :button-1 :button-2 :button-3 :button-4 :button-5)))
  251.  
  252. (deftype gcontext-key ()
  253.   '(member :function :plane-mask :foreground :background
  254.        :line-width :line-style :cap-style :join-style :fill-style :fill-rule
  255.        :arc-mode :tile :stipple :ts-x :ts-y :font :subwindow-mode
  256.        :exposures :clip-x :clip-y :clip-mask :dash-offset :dashes))
  257.  
  258. (deftype event-key ()
  259.   '(member :key-press :key-release :button-press :button-release :motion-notify
  260.        :enter-notify :leave-notify :focus-in :focus-out :keymap-notify
  261.        :exposure :graphics-exposure :no-exposure :visibility-notify
  262.        :create-notify :destroy-notify :unmap-notify :map-notify :map-request
  263.        :reparent-notify :configure-notify :gravity-notify :resize-request
  264.        :configure-request :circulate-notify :circulate-request :property-notify
  265.        :selection-clear :selection-request :selection-notify
  266.        :colormap-notify :client-message))
  267.  
  268. (deftype error-key ()
  269.   '(member :access :alloc :atom :colormap :cursor :drawable :font :gcontext :id-choice
  270.        :illegal-request :implementation :length :match :name :pixmap :value :window))
  271.  
  272. (deftype draw-direction ()
  273.   '(member :left-to-right :right-to-left))
  274.  
  275. (defstruct bitmap-format
  276.   (unit <unspec> :type (member 8 16 32))
  277.   (pad <unspec> :type (member 8 16 32))
  278.   (lsb-first-p <unspec> :type boolean))
  279.  
  280. (defstruct pixmap-format
  281.   (depth <unspec> :type image-depth)
  282.   (bits-per-pixel <unspec> :type (member 1 4 8 16 24 32))
  283.   (pad <unspec> :type (member 8 16 32)))
  284.  
  285. (defstruct visual-info
  286.   (id <unspec> :type card29)
  287.   (class <unspec> :type (member :static-gray :static-color :true-color
  288.                 :gray-scale :pseudo-color :direct-color))
  289.   (red-mask <unspec> :type pixel)
  290.   (green-mask <unspec> :type pixel)
  291.   (blue-mask <unspec> :type pixel)
  292.   (bits-per-rgb <unspec> :type card8)
  293.   (colormap-entries <unspec> :type card16))
  294.  
  295. (defstruct screen
  296.   (root <unspec> :type window)
  297.   (width <unspec> :type card16)
  298.   (height <unspec> :type card16)
  299.   (width-in-millimeters <unspec> :type card16)
  300.   (height-in-millimeters <unspec> :type card16)
  301.   (depths <unspec> :type (alist (image-depth depth) ((list visual-info) visuals)))
  302.   (root-depth <unspec> :type image-depth)
  303.   (root-visual <unspec> :type card29)
  304.   (default-colormap <unspec> :type colormap)
  305.   (white-pixel <unspec> :type pixel)
  306.   (black-pixel <unspec> :type pixel)
  307.   (min-installed-maps <unspec> :type card16)
  308.   (max-installed-maps <unspec> :type card16)
  309.   (backing-stores <unspec> :type (member :never :when-mapped :always))
  310.   (save-unders-p <unspec> :type boolean)
  311.   (event-mask-at-open <unspec> :type mask32))
  312.  
  313. ;; The list contains alternating keywords and integers.
  314.  
  315. (deftype font-props () 'list)
  316.  
  317. (defun open-display (host &key (display 0) protocol)
  318.   ;; A string must be acceptable as a host, but otherwise the possible types for host
  319.   ;; and protocol are not constrained, and will likely be very system dependent.  The
  320.   ;; default protocol is system specific.  Authorization, if any, is assumed to come
  321.   ;; from the environment somehow.
  322.   (declare (type integer display)
  323.        (values display)))
  324.  
  325. (defun display-protocol-major-version (display)
  326.   (declare (type display display)
  327.        (values card16)))
  328.  
  329. (defun display-protocol-minor-version (display)
  330.   (declare (type display display)
  331.        (values card16)))
  332.  
  333. (defun display-vendor-name (display)
  334.   (declare (type display display)
  335.        (values string)))
  336.  
  337. (defun display-release-number (display)
  338.   (declare (type display display)
  339.        (values card32)))
  340.  
  341. (defun display-image-lsb-first-p (display)
  342.   (declare (type display display)
  343.        (values boolean)))
  344.  
  345. (defun display-bitmap-formap (display)
  346.   (declare (type display display)
  347.        (values bitmap-format)))
  348.  
  349. (defun display-pixmap-formats (display)
  350.   (declare (type display display)
  351.        (values (list pixmap-formats))))
  352.  
  353. (defun display-roots (display)
  354.   (declare (type display display)
  355.        (values (list screen))))
  356.  
  357. (defun display-motion-buffer-size (display)
  358.   (declare (type display display)
  359.        (values card32)))
  360.  
  361. (defun display-max-request-length (display)
  362.   (declare (type display display)
  363.        (values card16)))
  364.  
  365. (defun display-min-keycode (display)
  366.   (declare (type display display)
  367.        (values card8)))
  368.  
  369. (defun display-max-keycode (display)
  370.   (declare (type display display)
  371.        (values card8)))
  372.  
  373. (defun close-display (display)
  374.   (declare (type display display)))
  375.  
  376. (defun display-error-handler (display)
  377.   (declare (type display display)
  378.        (values handler)))
  379.  
  380. (defsetf display-error-handler (display) (handler)
  381.   ;; All errors (synchronous and asynchronous) are processed by calling an error
  382.   ;; handler in the display.  If handler is a sequence it is expected to contain
  383.   ;; handler functions specific to each error; the error code is used to index the
  384.   ;; sequence, fetching the appropriate handler.  Any results returned by the handler
  385.   ;; are ignored; it is assumed the handler either takes care of the error
  386.   ;; completely, or else signals. For all core errors, the keyword/value argument
  387.   ;; pairs are:
  388.   ;;    :major card8
  389.   ;;    :minor card16
  390.   ;;    :sequence card16
  391.   ;;    :current-sequence card16
  392.   ;; For :colormap, :cursor, :drawable, :font, :gcontext, :id-choice, :pixmap, and
  393.   ;; :window errors another pair is:
  394.   ;;    :resource-id card32
  395.   ;; For :atom errors, another pair is:
  396.   ;;    :atom-id card32
  397.   ;; For :value errors, another pair is:
  398.   ;;    :value card32
  399.   (declare (type display display)
  400.        (type (or (sequence (function (display symbol &rest key-vals)))
  401.              (function (display symbol &rest key-vals)))
  402.          handler)))
  403.  
  404. (defmacro define-condition (name base &body items)
  405.   ;; just a place-holder here for the real thing
  406.   )
  407.  
  408. (define-condition request-error error
  409.   display
  410.   major
  411.   minor
  412.   sequence
  413.   current-sequence)
  414.  
  415. (defun default-error-handler (display error-key &rest key-vals)
  416.   ;; The default display-error-handler.
  417.   ;; It signals the conditions listed below.
  418.   (declare (type display display)
  419.        (type symbol error-key))
  420.   )
  421.  
  422. (define-condition resource-error request-error
  423.   resource-id)
  424.  
  425. (define-condition access-error request-error)
  426.  
  427. (define-condition alloc-error request-error)
  428.  
  429. (define-condition atom-error request-error
  430.   atom-id)
  431.  
  432. (define-condition colormap-error resource-error)
  433.  
  434. (define-condition cursor-error resource-error)
  435.  
  436. (define-condition drawable-error resource-error)
  437.  
  438. (define-condition font-error resource-error)
  439.  
  440. (define-condition gcontext-error resource-error)
  441.  
  442. (define-condition id-choice-error resource-error)
  443.  
  444. (define-condition illegal-request-error request-error)
  445.  
  446. (define-condition implementation-error request-error)
  447.  
  448. (define-condition length-error request-error)
  449.  
  450. (define-condition match-error request-error)
  451.  
  452. (define-condition name-error request-error)
  453.  
  454. (define-condition pixmap-error resource-error)
  455.  
  456. (define-condition value-error request-error
  457.   value)
  458.  
  459. (define-condition window-error resource-error)
  460.  
  461. (defmacro with-display ((display) &body body)
  462.   ;; This macro is for use in a multi-process environment.  It provides exclusive
  463.   ;; access to the local display object for multiple request generation.  It need not
  464.   ;; provide immediate exclusive access for replies; that is, if another process is
  465.   ;; waiting for a reply (while not in a with-display), then synchronization need not
  466.   ;; (but can) occur immediately.  Except where noted, all routines effectively
  467.   ;; contain an implicit with-display where needed, so that correct synchronization
  468.   ;; is always provided at the interface level on a per-call basis.  Nested uses of
  469.   ;; this macro will work correctly.  This macro does not prevent concurrent event
  470.   ;; processing; see with-event-queue.
  471.   )
  472.  
  473. (defun display-force-output (display)
  474.   ;; Output is normally buffered; this forces any buffered output.
  475.   (declare (type display display)))
  476.  
  477. (defun display-finish-output (display)
  478.   ;; Forces output, then causes a round-trip to ensure that all possible errors and
  479.   ;; events have been received.
  480.   (declare (type display display)))
  481.  
  482. (defun display-after-function (display)
  483.   ;; setf'able
  484.   ;; If defined, called after every protocol request is generated, even those inside
  485.   ;; explicit with-display's, but never called from inside the after-function itself.
  486.   ;; The function is called inside the effective with-display for the associated
  487.   ;; request.  Default value is nil.  Can be set, for example, to
  488.   ;; #'display-force-output or #'display-finish-output.
  489.   (declare (type display display)
  490.        (values (or null (function (display))))))
  491.  
  492. (defun create-window (&key parent x y width height (depth 0) (border-width 0)
  493.               (class :copy) (visual :copy)
  494.               background border gravity bit-gravity
  495.               backing-store backing-planes backing-pixel save-under
  496.               event-mask do-not-propagate-mask override-redirect
  497.               colormap cursor)
  498.   ;; Display is obtained from parent.  Only non-nil attributes are passed on in the
  499.   ;; request: the function makes no assumptions about what the actual protocol
  500.   ;; defaults are.  Width and height are the inside size, excluding border.
  501.   (declare (type window parent)
  502.        (type int16 x y)
  503.        (type card16 width height depth border-width)
  504.        (type (member :copy :input-output :input-only) class)
  505.        (type (or (member :copy) visual) visual)
  506.        (type (or null (member :none :parent-relative) pixel pixmap) background)
  507.        (type (or null (member :copy) pixel pixmap) border)
  508.        (type (or null win-gravity) gravity)
  509.        (type (or null bit-gravity) bit-gravity)
  510.        (type (or null (member :not-useful :when-mapped :always) backing-store))
  511.        (type (or null pixel) backing-planes backing-pixel)
  512.        (type (or null event-mask) event-mask)
  513.        (type (or null device-event-mask) do-not-propagate-mask)
  514.        (type (or null (member :on :off)) save-under override-redirect)
  515.        (type (or null (member :copy) colormap) colormap)
  516.        (type (or null (member :none) cursor) cursor)
  517.        (values window)))
  518.  
  519. (defun window-class (window)
  520.   (declare (type window window)
  521.        (values (member :input-output :input-only))))
  522.  
  523. (defun window-visual (window)
  524.   (declare (type window window)
  525.        (values card29)))
  526.  
  527. (defsetf window-background (window) (background)
  528.   (declare (type window window)
  529.        (type (or (member :none :parent-relative) pixel pixmap) background)))
  530.  
  531. (defsetf window-border (window) (border)
  532.   (declare (type window window)
  533.        (type (or (member :copy) pixel pixmap) border)))
  534.  
  535. (defun window-gravity (window)
  536.   ;; setf'able
  537.   (declare (type window window)
  538.        (values win-gravity)))
  539.  
  540. (defun window-bit-gravity (window)
  541.   ;; setf'able
  542.   (declare (type window window)
  543.        (values bit-gravity)))
  544.  
  545. (defun window-backing-store (window)
  546.   ;; setf'able
  547.   (declare (type window window)
  548.        (values (member :not-useful :when-mapped :always))))
  549.  
  550. (defun window-backing-planes (window)
  551.   ;; setf'able
  552.   (declare (type window window)
  553.        (values pixel)))
  554.  
  555. (defun window-backing-pixel (window)
  556.   ;; setf'able
  557.   (declare (type window window)
  558.        (values pixel)))
  559.  
  560. (defun window-save-under (window)
  561.   ;; setf'able
  562.   (declare (type window window)
  563.        (values (member :on :off))))
  564.  
  565. (defun window-event-mask (window)
  566.   ;; setf'able
  567.   (declare (type window window)
  568.        (values mask32)))
  569.  
  570. (defun window-do-not-propagate-mask (window)
  571.   ;; setf'able
  572.   (declare (type window window)
  573.        (values mask32)))
  574.  
  575. (defun window-override-redirect (window)
  576.   ;; setf'able
  577.   (declare (type window window)
  578.        (values (member :on :off))))
  579.  
  580. (defun window-colormap (window)
  581.   (declare (type window window)
  582.        (values (or null colormap))))
  583.  
  584. (defsetf window-colormap (window) (colormap)
  585.   (declare (type window window)
  586.        (type (or (member :copy) colormap) colormap)))
  587.  
  588. (defsetf window-cursor (window) (cursor)
  589.   (declare (type window window)
  590.        (type (or (member :none) cursor) cursor)))
  591.  
  592. (defun window-colormap-installed-p (window)
  593.   (declare (type window window)
  594.        (values boolean)))
  595.  
  596. (defun window-all-event-masks (window)
  597.   (declare (type window window)
  598.        (values mask32)))
  599.  
  600. (defun window-map-state (window)
  601.   (declare (type window window)
  602.        (values (member :unmapped :unviewable :viewable))))
  603.  
  604. (defsetf drawable-x (window) (x)
  605.   (declare (type window window)
  606.        (type int16 x)))
  607.  
  608. (defsetf drawable-y (window) (y)
  609.   (declare (type window window)
  610.        (type int16 y)))
  611.  
  612. (defsetf drawable-width (window) (width)
  613.   ;; Inside width, excluding border.
  614.   (declare (type window window)
  615.        (type card16 width)))
  616.  
  617. (defsetf drawable-height (window) (height)
  618.   ;; Inside height, excluding border.
  619.   (declare (type window window)
  620.        (type card16 height)))
  621.  
  622. (defsetf drawable-border-width (window) (border-width)
  623.   (declare (type window window)
  624.        (type card16 border-width)))
  625.  
  626. (defsetf window-priority (window &optional sibling) (mode)
  627.   ;; A bit strange, but retains setf form.
  628.   (declare (type window window)
  629.        (type (or null window) sibling)
  630.        (type (member :above :below :top-if :bottom-if :opposite) mode)))
  631.  
  632. (defmacro with-state ((drawable) &body body)
  633.   ;; Allows a consistent view to be obtained of data returned by GetWindowAttributes
  634.   ;; and GetGeometry, and allows a coherent update using ChangeWindowAttributes and
  635.   ;; ConfigureWindow.  The body is not surrounded by a with-display.  Within the
  636.   ;; indefinite scope of the body, on a per-process basis in a multi-process
  637.   ;; environment, the first call within an Accessor Group on the specified drawable
  638.   ;; (the object, not just the variable) causes the complete results of the protocol
  639.   ;; request to be retained, and returned in any subsequent accessor calls.  Calls
  640.   ;; within a Setf Group are delayed, and executed in a single request on exit from
  641.   ;; the body.  In addition, if a call on a function within an Accessor Group follows
  642.   ;; a call on a function in the corresponding Setf Group, then all delayed setfs for
  643.   ;; that group are executed, any retained accessor information for that group is
  644.   ;; discarded, the corresponding protocol request is (re)issued, and the results are
  645.   ;; (again) retained, and returned in any subsequent accessor calls.
  646.  
  647.   ;; Accessor Group A (for GetWindowAttributes):
  648.   ;; window-visual, window-class, window-gravity, window-bit-gravity,
  649.   ;; window-backing-store, window-backing-planes, window-backing-pixel,
  650.   ;; window-save-under, window-colormap, window-colormap-installed-p,
  651.   ;; window-map-state, window-all-event-masks, window-event-mask,
  652.   ;; window-do-not-propagate-mask, window-override-redirect
  653.  
  654.   ;; Setf Group A (for ChangeWindowAttributes):
  655.   ;; window-gravity, window-bit-gravity, window-backing-store, window-backing-planes,
  656.   ;; window-backing-pixel, window-save-under, window-event-mask,
  657.   ;; window-do-not-propagate-mask, window-override-redirect, window-colormap,
  658.   ;; window-cursor
  659.  
  660.   ;; Accessor Group G (for GetGeometry):
  661.   ;; drawable-root, drawable-depth, drawable-x, drawable-y, drawable-width,
  662.   ;; drawable-height, drawable-border-width
  663.  
  664.   ;; Setf Group G (for ConfigureWindow):
  665.   ;; drawable-x, drawable-y, drawable-width, drawable-height, drawable-border-width,
  666.   ;; window-priority
  667.   )
  668.  
  669. (defun destroy-window (window)
  670.   (declare (type window window)))
  671.  
  672. (defun destroy-subwindows (window)
  673.   (declare (type window window)))
  674.  
  675. (defun add-to-save-set (window)
  676.   (declare (type window window)))
  677.  
  678. (defun remove-from-save-set (window)
  679.   (declare (type window window)))
  680.  
  681. (defun reparent-window (window parent x y)
  682.   (declare (type window window parent)
  683.        (type int16 x y)))
  684.  
  685. (defun map-window (window)
  686.   (declare (type window window)))
  687.  
  688. (defun map-subwindows (window)
  689.   (declare (type window window)))
  690.  
  691. (defun unmap-window (window)
  692.   (declare (type window window)))
  693.  
  694. (defun unmap-subwindows (window)
  695.   (declare (type window window)))
  696.  
  697. (defun circulate-window-up (window)
  698.   (declare (type window window)))
  699.  
  700. (defun circulate-window-down (window)
  701.   (declare (type window window)))
  702.  
  703. (defun drawable-root (drawable)
  704.   (declare (type drawable drawable)
  705.        (values window)))
  706.  
  707. (defun drawable-depth (drawable)
  708.   (declare (type drawable drawable)
  709.        (values card8)))
  710.  
  711. (defun drawable-x (drawable)
  712.   (declare (type drawable drawable)
  713.        (values int16)))
  714.  
  715. (defun drawable-y (drawable)
  716.   (declare (type drawable drawable)
  717.        (values int16)))
  718.  
  719. (defun drawable-width (drawable)
  720.   ;; For windows, inside width, excluding border.
  721.   (declare (type drawable drawable)
  722.        (values card16)))
  723.  
  724. (defun drawable-height (drawable)
  725.   ;; For windows, inside height, excluding border.
  726.   (declare (type drawable drawable)
  727.        (values card16)))
  728.  
  729. (defun drawable-border-width (drawable)
  730.   (declare (type drawable drawable)
  731.        (values card16)))
  732.  
  733. (defun query-tree (window &key (result-type 'list))
  734.   (declare (type window window)
  735.        (type type result-type)
  736.        (values (sequence window) parent root)))
  737.  
  738. (defun change-property (window property data type format
  739.             &key (mode :replace) (start 0) end transform)
  740.   ;; Start and end affect sub-sequence extracted from data.
  741.   ;; Transform is applied to each extracted element.
  742.   (declare (type window window)
  743.        (type xatom property type)
  744.        (type (member 8 16 32) format)
  745.        (type sequence data)
  746.        (type (member :replace :prepend :append) mode)
  747.        (type array-index start)
  748.        (type (or null array-index) end)
  749.        (type (or null (function (t) integer)) transform)))
  750.  
  751. (defun delete-property (window property)
  752.   (declare (type window window)
  753.        (type xatom property)))
  754.  
  755. (defun get-property (window property
  756.              &key type (start 0) end delete-p (result-type 'list) transform)
  757.   ;; Transform is applied to each integer retrieved.
  758.   ;; Nil is returned for type when the protocol returns None.
  759.   (declare (type window window)
  760.        (type xatom property)
  761.        (type (or null xatom) type)
  762.        (type array-index start)
  763.        (type (or null array-index) end)
  764.        (type boolean delete-p)
  765.        (type type result-type)
  766.        (type (or null (function (integer) t)) transform)
  767.        (values data type format bytes-after)))
  768.  
  769. (defun rotate-properties (window properties &optional (delta 1))
  770.   ;; Postive rotates left, negative rotates right (opposite of actual protocol request).
  771.   (declare (type window window)
  772.        (type (sequence xatom) properties)
  773.        (type int16 delta)))
  774.  
  775. (defun list-properties (window &key (result-type 'list))
  776.   (declare (type window window)
  777.        (type type result-type)
  778.        (values (sequence keyword))))
  779.  
  780. ;; Although atom-ids are not visible in the normal user interface, atom-ids might
  781. ;; appear in window properties and other user data, so conversion hooks are needed.
  782.  
  783. (defun intern-atom (display name)
  784.   (declare (type display display)
  785.        (type xatom name)
  786.        (values card29)))
  787.  
  788. (defun find-atom (display name)
  789.   (declare (type display display)
  790.        (type xatom name)
  791.        (values (or null card29))))
  792.  
  793. (defun atom-name (display atom-id)
  794.   (declare (type display display)
  795.        (type card29 atom-id)
  796.        (values keyword)))
  797.  
  798. (defun selection-owner (display selection)
  799.   (declare (type display display)
  800.        (type xatom selection)
  801.        (values (or null window))))
  802.  
  803. (defsetf selection-owner (display selection &optional time) (owner)
  804.   ;; A bit strange, but retains setf form.
  805.   (declare (type display display)
  806.        (type xatom selection)
  807.        (type (or null window) owner)
  808.        (type timestamp time)))
  809.  
  810. (defun convert-selection (selection type requestor &optional property time)
  811.   (declare (type xatom selection type)
  812.        (type window requestor)
  813.        (type (or null xatom) property)
  814.        (type timestamp time)))
  815.  
  816. (defun send-event (window event-key event-mask &rest args
  817.            &key propagate-p display &allow-other-keys)
  818.   ;; Additional arguments depend on event-key, and are as specified further below
  819.   ;; with declare-event, except that both resource-ids and resource objects are
  820.   ;; accepted in the event components.  The display argument is only required if the
  821.   ;; window is :pointer-window or :input-focus.  If an argument has synonyms, it is
  822.   ;; only necessary to supply a value for one of them; it is an error to specify
  823.   ;; different values for synonyms.
  824.   (declare (type (or window (member :pointer-window :input-focus)) window)
  825.        (type (or null event-key) event-key)
  826.        (type event-mask event-mask)
  827.        (type boolean propagate-p)
  828.        (type (or null display) display)))
  829.  
  830. (defun grab-pointer (window event-mask
  831.              &key owner-p sync-pointer-p sync-keyboard-p confine-to cursor time)
  832.   (declare (type window window)
  833.        (type pointer-event-mask event-mask)
  834.        (type boolean owner-p sync-pointer-p sync-keyboard-p)
  835.        (type (or null window) confine-to)
  836.        (type (or null cursor) cursor)
  837.        (type timestamp time)
  838.        (values grab-status)))
  839.  
  840. (defun ungrab-pointer (display &key time)
  841.   (declare (type display display)
  842.        (type timestamp time)))
  843.  
  844. (defun grab-button (window button event-mask
  845.             &key (modifiers 0)
  846.              owner-p sync-pointer-p sync-keyboard-p confine-to cursor)
  847.   (declare (type window window)
  848.        (type (or (member :any) card8) button)
  849.        (type modifier-mask modifiers)
  850.        (type pointer-event-mask event-mask)
  851.        (type boolean owner-p sync-pointer-p sync-keyboard-p)
  852.        (type (or null window) confine-to)
  853.        (type (or null cursor) cursor)))
  854.  
  855. (defun ungrab-button (window button &key (modifiers 0))
  856.   (declare (type window window)
  857.        (type (or (member :any) card8) button)
  858.        (type modifier-mask modifiers)))
  859.  
  860. (defun change-active-pointer-grab (display event-mask &optional cursor time)
  861.   (declare (type display display)
  862.        (type pointer-event-mask event-mask)
  863.        (type (or null cursor) cursor)
  864.        (type timestamp time)))
  865.  
  866. (defun grab-keyboard (window &key owner-p sync-pointer-p sync-keyboard-p time)
  867.   (declare (type window window)
  868.        (type boolean owner-p sync-pointer-p sync-keyboard-p)
  869.        (type timestamp time)
  870.        (values grab-status)))
  871.  
  872. (defun ungrab-keyboard (display &key time)
  873.   (declare (type display display)
  874.        (type timestamp time)))
  875.  
  876. (defun grab-key (window key &key (modifiers 0) owner-p sync-pointer-p sync-keyboard-p)
  877.   (declare (type window window)
  878.        (type boolean owner-p sync-pointer-p sync-keyboard-p)
  879.        (type (or (member :any) card8) key)
  880.        (type modifier-mask modifiers)))
  881.  
  882. (defun ungrab-key (window key &key (modifiers 0))
  883.   (declare (type window window)
  884.        (type (or (member :any) card8) key)
  885.        (type modifier-mask modifiers)))
  886.  
  887. (defun allow-events (display mode &optional time)
  888.   (declare (type display display)
  889.        (type (member :async-pointer :sync-pointer :reply-pointer
  890.              :async-keyboard :sync-keyboard :replay-keyboard
  891.              :async-both :sync-both)
  892.          mode)
  893.        (type timestamp time)))
  894.  
  895. (defun grab-server (display)
  896.   (declare (type display display)))
  897.  
  898. (defun ungrab-server (display)
  899.   (declare (type display display)))
  900.  
  901. (defmacro with-server-grabbed ((display) &body body)
  902.   ;; The body is not surrounded by a with-display.
  903.   )
  904.  
  905. (defun query-pointer (window)
  906.   (declare (type window window)
  907.        (values x y same-screen-p child mask root-x root-y root)))
  908.  
  909. (defun pointer-position (window)
  910.   (declare (type window window)
  911.        (values x y same-screen-p)))
  912.  
  913. (defun global-pointer-position (display)
  914.   (declare (type display display)
  915.        (values root-x root-y root)))
  916.  
  917. (defun motion-events (window &key start stop (result-type 'list))
  918.   (declare (type window window)
  919.        (type timestamp start stop)
  920.        (type type result-type)
  921.        (values (repeat-seq (int16 x) (int16 y) (timestamp time)))))
  922.  
  923. (defun translate-coordinates (src src-x src-y dst)
  924.   ;; If src and dst are not on the same screen, nil is returned.
  925.   (declare (type window src)
  926.        (type int16 src-x src-y)
  927.        (type window dst)
  928.        (values dst-x dst-y child)))
  929.  
  930. (defun warp-pointer (dst dst-x dst-y)
  931.   (declare (type window dst)
  932.        (type int16 dst-x dst-y)))
  933.  
  934. (defun warp-pointer-relative (display x-off y-off)
  935.   (declare (type display display)
  936.        (type int16 x-off y-off)))
  937.  
  938. (defun warp-pointer-if-inside (dst dst-x dst-y src src-x src-y
  939.                    &optional src-width src-height)
  940.   ;; Passing in a zero src-width or src-height is a no-op.  A null src-width or
  941.   ;; src-height translates into a zero value in the protocol request.
  942.   (declare (type window dst src)
  943.        (type int16 dst-x dst-y src-x src-y)
  944.        (type (or null card16) src-width src-height)))
  945.  
  946. (defun warp-pointer-relative-if-inside (x-off y-off src src-x src-y
  947.                     &optional src-width src-height)
  948.   ;; Passing in a zero src-width or src-height is a no-op.  A null src-width or
  949.   ;; src-height translates into a zero value in the protocol request.
  950.   (declare (type window src)
  951.        (type int16 x-off y-off src-x src-y)
  952.        (type (or null card16) src-width src-height)))
  953.  
  954. (defun set-input-focus (display focus revert-to &optional time)
  955.   ;; Setf ought to allow multiple values.
  956.   (declare (type display display)
  957.        (type (or (member :none :pointer-root) window) focus)
  958.        (type (member :none :parent :pointer-root) revert-to)
  959.        (type timestamp time)))
  960.  
  961. (defun input-focus (display)
  962.   (declare (type display display)
  963.        (values focus revert-to)))
  964.  
  965. (defun query-keymap (display)
  966.   (declare (type display display)
  967.        (values (bit-vector 256))))
  968.  
  969. (defun open-font (display name)
  970.   ;; Font objects may be cached and reference counted locally within the display
  971.   ;; object.  This function might not execute a with-display if the font is cached.
  972.   ;; The protocol QueryFont request happens on-demand under the covers.
  973.   (declare (type display display)
  974.        (type stringable name)
  975.        (values font)))
  976.  
  977. ;; We probably want a per-font bit to indicate whether caching on
  978. ;; text-extents/width calls is desirable.  But what to name it?
  979.  
  980. (defun discard-font-info (font)
  981.   ;; Discards any state that can be re-obtained with QueryFont.  This is simply
  982.   ;; a performance hint for memory-limited systems.
  983.   (declare (type font font)))
  984.  
  985. ;; This can be signalled anywhere a pseudo font access fails.
  986.  
  987. (define-condition invalid-font error
  988.   font)
  989.  
  990. ;; Note: font-font-info removed.
  991.  
  992. (defun font-name (font)
  993.   ;; Returns nil for a pseudo font returned by gcontext-font.
  994.   (declare (type font font)
  995.        (values (or null string))))
  996.  
  997. (defun font-direction (font)
  998.   (declare (type font font)
  999.        (values draw-direction)))
  1000.  
  1001. (defun font-min-char (font)
  1002.   (declare (type font font)
  1003.        (values card16)))
  1004.  
  1005. (defun font-max-char (font)
  1006.   (declare (type font font)
  1007.        (values card16)))
  1008.  
  1009. (defun font-min-byte1 (font)
  1010.   (declare (type font font)
  1011.        (values card8)))
  1012.  
  1013. (defun font-max-byte1 (font)
  1014.   (declare (type font font)
  1015.        (values card8)))
  1016.  
  1017. (defun font-min-byte2 (font)
  1018.   (declare (type font font)
  1019.        (values card8)))
  1020.  
  1021. (defun font-max-byte2 (font)
  1022.   (declare (type font font)
  1023.        (values card8)))
  1024.  
  1025. (defun font-all-chars-exist-p (font)
  1026.   (declare (type font font)
  1027.        (values boolean)))
  1028.  
  1029. (defun font-default-char (font)
  1030.   (declare (type font font)
  1031.        (values card16)))
  1032.  
  1033. (defun font-ascent (font)
  1034.   (declare (type font font)
  1035.        (values int16)))
  1036.  
  1037. (defun font-descent (font)
  1038.   (declare (type font font)
  1039.        (values int16)))
  1040.  
  1041. ;; The list contains alternating keywords and int32s.
  1042.  
  1043. (deftype font-props () 'list)
  1044.  
  1045. (defun font-properties (font)
  1046.   (declare (type font font)
  1047.        (values font-props)))
  1048.  
  1049. (defun font-property (font name)
  1050.   (declare (type font font)
  1051.        (type keyword name)
  1052.        (values (or null int32))))
  1053.  
  1054. ;; For each of left-bearing, right-bearing, width, ascent, descent, attributes:
  1055.  
  1056. (defun char-<metric> (font index)
  1057.   ;; Note: I have tentatively chosen to return nil for an out-of-bounds index
  1058.   ;; (or an in-bounds index on a pseudo font), although returning zero or
  1059.   ;; signalling might be better.
  1060.   (declare (type font font)
  1061.        (type card16 index)
  1062.        (values (or null int16))))
  1063.  
  1064. (defun max-char-<metric> (font)
  1065.   ;; Note: I have tentatively chosen separate accessors over allowing :min and
  1066.   ;; :max as an index above.
  1067.   (declare (type font font)
  1068.        (values int16)))
  1069.  
  1070. (defun min-char-<metric> (font)
  1071.   (declare (type font font)
  1072.        (values int16)))
  1073.  
  1074. ;; Note: char16-<metric> accessors could be defined to accept two-byte indexes.
  1075.  
  1076. (defun close-font (font)
  1077.   ;; This might not generate a protocol request if the font is reference
  1078.   ;; counted locally or if it is a pseudo font.
  1079.   (declare (type font font)))
  1080.  
  1081. (defun list-font-names (display pattern &key (max-fonts 65535) (result-type 'list))
  1082.   (declare (type display display)
  1083.        (type string pattern)
  1084.        (type card16 max-fonts)
  1085.        (type type result-type)
  1086.        (values (sequence string))))
  1087.  
  1088. (defun list-fonts (display pattern &key (max-fonts 65535) (result-type 'list))
  1089.   ;; Returns "pseudo" fonts that contain basic font metrics and properties, but
  1090.   ;; no per-character metrics and no resource-ids.  These pseudo fonts will be
  1091.   ;; converted (internally) to real fonts dynamically as needed, by issuing an
  1092.   ;; OpenFont request.  However, the OpenFont might fail, in which case the
  1093.   ;; invalid-font error can arise.
  1094.   (declare (type display display)
  1095.        (type string pattern)
  1096.        (type card16 max-fonts)
  1097.        (type type result-type)
  1098.        (values (sequence font))))
  1099.  
  1100. (defun font-path (display &key (result-type 'list))
  1101.   (declare (type display display)
  1102.        (type type result-type)
  1103.        (values (sequence (or string pathname)))))
  1104.  
  1105. (defsetf font-path (display) (paths)
  1106.   (declare (type display display)
  1107.        (type (sequence (or string pathname)) paths)))
  1108.  
  1109. (defun create-pixmap (&key width height depth drawable)
  1110.   (declare (type card16 width height)
  1111.        (type card8 depth)
  1112.        (type drawable drawable)
  1113.        (values pixmap)))
  1114.  
  1115. (defun free-pixmap (pixmap)
  1116.   (declare (type pixmap pixmap)))
  1117.  
  1118. (defun create-gcontext (&key drawable function plane-mask foreground background
  1119.                  line-width line-style cap-style join-style fill-style fill-rule
  1120.                  arc-mode tile stipple ts-x ts-y font subwindow-mode
  1121.                  exposures clip-x clip-y clip-mask clip-ordering
  1122.                  dash-offset dashes
  1123.                  (cache-p t))
  1124.   ;; Only non-nil components are passed on in the request, but for effective caching
  1125.   ;; assumptions have to be made about what the actual protocol defaults are.  For
  1126.   ;; all gcontext components, a value of nil causes the default gcontext value to be
  1127.   ;; used.  For clip-mask, this implies that an empty rect-seq cannot be represented
  1128.   ;; as a list.  Note:  use of stringable as font will cause an implicit open-font.
  1129.   ;; Note:  papers over protocol SetClipRectangles and SetDashes special cases.  If
  1130.   ;; cache-p is true, then gcontext state is cached locally, and changing a gcontext
  1131.   ;; component will have no effect unless the new value differs from the cached
  1132.   ;; value.  Component changes (setfs and with-gcontext) are always deferred
  1133.   ;; regardless of the cache mode, and sent over the protocol only when required by a
  1134.   ;; local operation or by an explicit call to force-gcontext-changes.
  1135.   (declare (type drawable drawable)
  1136.        (type (or null boole-constant) function)
  1137.        (type (or null pixel) plane-mask foreground background)
  1138.        (type (or null card16) line-width dash-offset)
  1139.        (type (or null int16) ts-x ts-y clip-x clip-y)
  1140.        (type (or null (member :solid :dash :double-dash)) line-style)
  1141.        (type (or null (member :not-last :butt :round :projecting)) cap-style)
  1142.        (type (or null (member :miter :round :bevel)) join-style)
  1143.        (type (or null (member :solid :tiled :opaque-stippled :stippled)) fill-style)
  1144.        (type (or null (member :even-odd :winding)) fill-rule)
  1145.        (type (or null (member :chord :pie-slice)) arc-mode)
  1146.        (type (or null pixmap) tile stipple)
  1147.        (type (or null fontable) font)
  1148.        (type (or null (member :clip-by-children :include-inferiors)) subwindow-mode)
  1149.        (type (or null (member :on :off)) exposures)
  1150.        (type (or null (member :none) pixmap rect-seq) clip-mask)
  1151.        (type (or null (member :unsorted :y-sorted :yx-sorted :yx-banded)) clip-ordering)
  1152.        (type (or null (or card8 (sequence card8))) dashes)
  1153.        (type boolean cache)
  1154.        (values gcontext)))
  1155.  
  1156. ;; For each argument to create-gcontext (except font, clip-mask and
  1157. ;; clip-ordering) declared as (type <type> <name>), there is an accessor:
  1158.  
  1159. (defun gcontext-<name> (gcontext)
  1160.   ;; The value will be nil if the last value stored is unknown (e.g., the cache was
  1161.   ;; off, or the component was copied from a gcontext with unknown state).
  1162.   (declare (type gcontext gcontext)
  1163.        (values <type>)))
  1164.  
  1165. ;; For each argument to create-gcontext (except clip-mask and clip-ordering) declared
  1166. ;; as (type (or null <type>) <name>), there is a setf for the corresponding accessor:
  1167.  
  1168. (defsetf gcontext-<name> (gcontext) (value)
  1169.   (declare (type gcontext gcontext)
  1170.        (type <type> value)))
  1171.  
  1172. (defun gcontext-font (gcontext &optional metrics-p)
  1173.   ;; If the stored font is known, it is returned.  If it is not known and
  1174.   ;; metrics-p is false, then nil is returned.  If it is not known and
  1175.   ;; metrics-p is true, then a pseudo font is returned.  Full metric and
  1176.   ;; property information can be obtained, but the font does not have a name or
  1177.   ;; a resource-id, and attempts to use it where a resource-id is required will
  1178.   ;; result in an invalid-font error.
  1179.   (declare (type gcontext gcontext)
  1180.        (type boolean metrics-p)
  1181.        (values (or null font))))
  1182.  
  1183. (defun gcontext-clip-mask (gcontext)
  1184.   (declare (type gcontext gcontext)
  1185.        (values (or null (member :none) pixmap rect-seq)
  1186.            (or null (member :unsorted :y-sorted :yx-sorted :yx-banded)))))
  1187.  
  1188. (defsetf gcontext-clip-mask (gcontext &optional ordering) (clip-mask)
  1189.   ;; Is nil illegal here, or is it transformed to a vector?
  1190.   ;; A bit strange, but retains setf form.
  1191.   (declare (type gcontext gcontext)
  1192.        (type (or null (member :unsorted :y-sorted :yx-sorted :yx-banded)) clip-ordering)
  1193.        (type (or (member :none) pixmap rect-seq) clip-mask)))
  1194.  
  1195. (defun force-gcontext-changes (gcontext)
  1196.   ;; Force any delayed changes.
  1197.   (declare (type gcontext gcontext)))
  1198.  
  1199. (defmacro with-gcontext ((gcontext &key
  1200.               function plane-mask foreground background
  1201.               line-width line-style cap-style join-style fill-style fill-rule
  1202.               arc-mode tile stipple ts-x ts-y font subwindow-mode
  1203.               exposures clip-x clip-y clip-mask clip-ordering
  1204.               dashes dash-offset)
  1205.              &body body)
  1206.   ;; Changes gcontext components within the dynamic scope of the body (i.e.,
  1207.   ;; indefinite scope and dynamic extent), on a per-process basis in a multi-process
  1208.   ;; environment.  The body is not surrounded by a with-display.  If cache-p is nil
  1209.   ;; or the some component states are unknown, this will implement save/restore by
  1210.   ;; creating a temporary gcontext and doing copy-gcontext-components to and from it.
  1211.   )
  1212.  
  1213. (defun copy-gcontext-components (src dst &rest keys)
  1214.   (declare (type gcontext src dst)
  1215.        (type (list gcontext-key) keys)))
  1216.  
  1217. (defun copy-gcontext (src dst)
  1218.   (declare (type gcontext src dst))
  1219.   ;; Copies all components.
  1220.   )
  1221.        
  1222. (defun free-gcontext (gcontext)
  1223.   (declare (type gcontext gcontext)))
  1224.  
  1225. (defun clear-area (window &key (x 0) (y 0) width height exposures-p)
  1226.   ;; Passing in a zero width or height is a no-op.  A null width or height translates
  1227.   ;; into a zero value in the protocol request.
  1228.   (declare (type window window)
  1229.        (type int16 x y)
  1230.        (type (or null card16) width height)
  1231.        (type boolean exposures-p)))
  1232.  
  1233. (defun copy-area (src gcontext src-x src-y width height dst dst-x dst-y)
  1234.   (declare (type drawable src dst)
  1235.        (type gcontext gcontext)
  1236.        (type int16 src-x src-y dst-x dst-y)
  1237.        (type card16 width height)))
  1238.  
  1239. (defun copy-plane (src gcontext plane src-x src-y width height dst dst-x dst-y)
  1240.   (declare (type drawable src dst)
  1241.        (type gcontext gcontext)
  1242.        (type pixel plane)
  1243.        (type int16 src-x src-y dst-x dst-y)
  1244.        (type card16 width height)))
  1245.  
  1246. (defun draw-point (drawable gcontext x y)
  1247.   ;; Should be clever about appending to existing buffered protocol request, provided
  1248.   ;; gcontext has not been modified.
  1249.   (declare (type drawable drawable)
  1250.        (type gcontext gcontext)
  1251.        (type int16 x y)))
  1252.  
  1253. (defun draw-points (drawable gcontext points &optional relative-p)
  1254.   (declare (type drawable drawable)
  1255.        (type gcontext gcontext)
  1256.        (type point-seq points)
  1257.        (type boolean relative-p)))
  1258.  
  1259. (defun draw-line (drawable gcontext x1 y1 x2 y2 &optional relative-p)
  1260.   ;; Should be clever about appending to existing buffered protocol request, provided
  1261.   ;; gcontext has not been modified.
  1262.   (declare (type drawable drawable)
  1263.        (type gcontext gcontext)
  1264.        (type int16 x1 y1 x2 y2)
  1265.        (type boolean relative-p)))
  1266.  
  1267. (defun draw-lines (drawable gcontext points &key relative-p fill-p (shape :complex))
  1268.   (declare (type drawable drawable)
  1269.        (type gcontext gcontext)
  1270.        (type point-seq points)
  1271.        (type boolean relative-p fill-p)
  1272.        (type (member :complex :non-convex :convex) shape)))
  1273.  
  1274. (defun draw-segments (drawable gcontext segments)
  1275.   (declare (type drawable drawable)
  1276.        (type gcontext gcontext)
  1277.        (type seg-seq segments)))
  1278.  
  1279. (defun draw-rectangle (drawable gcontext x y width height &optional fill-p)
  1280.   ;; Should be clever about appending to existing buffered protocol request, provided
  1281.   ;; gcontext has not been modified.
  1282.   (declare (type drawable drawable)
  1283.        (type gcontext gcontext)
  1284.        (type int16 x y)
  1285.        (type card16 width height)
  1286.        (type boolean fill-p)))
  1287.  
  1288. (defun draw-rectangles (drawable gcontext rectangles &optional fill-p)
  1289.   (declare (type drawable drawable)
  1290.        (type gcontext gcontext)
  1291.        (type rect-seq rectangles)
  1292.        (type boolean fill-p)))
  1293.  
  1294. (defun draw-arc (drawable gcontext x y width height angle1 angle2 &optional fill-p)
  1295.   ;; Should be clever about appending to existing buffered protocol request, provided
  1296.   ;; gcontext has not been modified.
  1297.   (declare (type drawable drawable)
  1298.        (type gcontext gcontext)
  1299.        (type int16 x y)
  1300.        (type card16 width height)
  1301.        (type angle angle1 angle2)
  1302.        (type boolean fill-p)))
  1303.  
  1304. (defun draw-arcs (drawable gcontext arcs &optional fill-p)
  1305.   (declare (type drawable drawable)
  1306.        (type gcontext gcontext)
  1307.        (type arc-seq arcs)
  1308.        (type boolean fill-p)))
  1309.  
  1310. ;; The following image routines are bare minimum.  It may be useful to define some
  1311. ;; form of "image" object to hide representation details and format conversions.  It
  1312. ;; also may be useful to provide stream-oriented interfaces for reading and writing
  1313. ;; the data.
  1314.  
  1315. (defun put-raw-image (drawable gcontext data
  1316.               &key (start 0) depth x y width height (left-pad 0) format)
  1317.   ;; Data must be a sequence of 8-bit quantities, already in the appropriate format
  1318.   ;; for transmission; the caller is responsible for all byte and bit swapping and
  1319.   ;; compaction.  Start is the starting index in data; the end is computed from the
  1320.   ;; other arguments.
  1321.   (declare (type drawable drawable)
  1322.        (type gcontext gcontext)
  1323.        (type (sequence card8) data)
  1324.        (type array-index start)
  1325.        (type card8 depth left-pad)
  1326.        (type int16 x y)
  1327.        (type card16 width height)
  1328.        (type (member :bitmap :xy-pixmap :z-pixmap) format)))
  1329.  
  1330. (defun get-raw-image (drawable &key data (start 0) x y width height
  1331.                     (plane-mask 0xffffffff) format
  1332.                     (result-type '(vector (unsigned-byte 8))))
  1333.   ;; If data is given, it is modified in place (and returned), otherwise a new
  1334.   ;; sequence is created and returned, with a size computed from the other arguments
  1335.   ;; and the returned depth.  The sequence is filled with 8-bit quantities, in
  1336.   ;; transmission format; the caller is responsible for any byte and bit swapping and
  1337.   ;; compaction required for further local use.
  1338.   (declare (type drawable drawable)
  1339.        (type (or null (sequence card8)) data)
  1340.        (type array-index start)
  1341.        (type int16 x y)
  1342.        (type card16 width height)
  1343.        (type pixel plane-mask)
  1344.        (type (member :xy-pixmap :z-pixmap) format)
  1345.        (values (sequence card8) depth visual)))
  1346.  
  1347. (defun translate-default (src src-start src-end font dst dst-start)
  1348.   ;; dst is guaranteed to have room for (- src-end src-start) integer elements,
  1349.   ;; starting at dst-start; whether dst holds 8-bit or 16-bit elements depends
  1350.   ;; on context.  font is the current font, if known.  The function should
  1351.   ;; translate as many elements of src as possible into indexes in the current
  1352.   ;; font, and store them into dst.  The first return value should be the src
  1353.   ;; index of the first untranslated element.  If no further elements need to
  1354.   ;; be translated, the second return value should be nil.  If a horizontal
  1355.   ;; motion is required before further translation, the second return value
  1356.   ;; should be the delta in x coordinate.  If a font change is required for
  1357.   ;; further translation, the second return value should be the new font.  If
  1358.   ;; known, the pixel width of the translated text can be returned as the third
  1359.   ;; value; this can allow for appending of subsequent output to the same
  1360.   ;; protocol request, if no overall width has been specified at the higher
  1361.   ;; level.
  1362.   (declare (type sequence src)
  1363.        (type array-index src-start src-end dst-start)
  1364.        (type (or null font) font)
  1365.        (type vector dst)
  1366.        (values array-index (or null int16 font) (or null int32))))
  1367.  
  1368. ;; There is a question below of whether translate should always be required, or
  1369. ;; if not, what the default should be or where it should come from.  For
  1370. ;; example, the default could be something that expected a string as src and
  1371. ;; translated the CL standard character set to ASCII indexes, and ignored fonts
  1372. ;; and bits.  Or the default could expect a string but otherwise be "system
  1373. ;; dependent".  Or the default could be something that expected a vector of
  1374. ;; integers and did no translation.  Or the default could come from the
  1375. ;; gcontext (but what about text-extents and text-width?).
  1376.  
  1377. (defun text-extents (fonts sequence &key (start 0) end translate)
  1378.   ;; If multiple fonts are involved, font-ascent and font-descent will be the
  1379.   ;; maximums.  If multiple directions are involved, the direction will be nil.
  1380.   ;; Translate will always be called with a 16-bit dst buffer.
  1381.   (declare (type sequence sequence)
  1382.        (type (or null font gcontext) font)
  1383.        (type translate translate)
  1384.        (values width ascent descent left right font-ascent font-descent direction
  1385.            (or null array-index))))
  1386.  
  1387. (defun text-width (font sequence &key (start 0) end translate)
  1388.   ;; Translate will always be called with a 16-bit dst buffer.
  1389.   (declare (type sequence sequence)
  1390.        (type (or null font gcontext) font)
  1391.        (type translate translate)
  1392.        (values int32 (or null array-index))))
  1393.  
  1394. ;; This controls the element size of the dst buffer given to translate.  If
  1395. ;; :default is specified, the size will be based on the current font, if known,
  1396. ;; and otherwise 16 will be used.  [An alternative would be to pass the buffer
  1397. ;; size to translate, and allow it to return the desired size if it doesn't
  1398. ;; like the current size.  The problem is that the protocol doesn't allow
  1399. ;; switching within a single request, so to allow switching would require
  1400. ;; knowing the width of text, which isn't necessarily known.  We could call
  1401. ;; text-width to compute it, but perhaps that is doing too many favors?]  [An
  1402. ;; additional possibility is to allow an index-size of :two-byte, in which case
  1403. ;; translate would be given a double-length 8-bit array, and translate would be
  1404. ;; expected to store first-byte/second-byte instead of 16-bit integers.]
  1405.  
  1406. (deftype index-size () '(member :default 8 16))
  1407.  
  1408. ;; In the glyph functions below, if width is specified, it is assumed to be the
  1409. ;; total pixel width of whatever string of glyphs is actually drawn.
  1410. ;; Specifying width will allow for appending the output of subsequent calls to
  1411. ;; the same protocol request, provided gcontext has not been modified in the
  1412. ;; interim.  If width is not specified, appending of subsequent output might
  1413. ;; not occur (unless translate returns the width).  Specifying width is simply
  1414. ;; a hint, for performance.
  1415.  
  1416. (defun draw-glyph (drawable gcontext x y elt
  1417.            &key translate width (size :default))
  1418.   ;; Returns true if elt is output, nil if translate refuses to output it.
  1419.   ;; Second result is width, if known.
  1420.   (declare (type drawable drawable)
  1421.        (type gcontext gcontext)
  1422.        (type int16 x y)
  1423.        (type translate translate)
  1424.        (type (or null int32) width)
  1425.        (type index-size size)
  1426.        (values boolean (or null int32))))
  1427.  
  1428. (defun draw-glyphs (drawable gcontext x y sequence
  1429.             &key (start 0) end translate width (size :default))
  1430.   ;; First result is new start, if end was not reached.  Second result is
  1431.   ;; overall width, if known.
  1432.   (declare (type drawable drawable)
  1433.        (type gcontext gcontext)
  1434.        (type int16 x y)
  1435.        (type sequence sequence)
  1436.        (type array-index start)
  1437.        (type (or null array-index) end)
  1438.        (type (or null int32) width)
  1439.        (type translate translate)
  1440.        (type index-size size)
  1441.        (values (or null array-index) (or null int32))))
  1442.  
  1443. (defun draw-image-glyph (drawable gcontext x y elt
  1444.              &key translate width (size :default))
  1445.   ;; Returns true if elt is output, nil if translate refuses to output it.
  1446.   ;; Second result is overall width, if known.  An initial font change is
  1447.   ;; allowed from translate.
  1448.   (declare (type drawable drawable)
  1449.        (type gcontext gcontext)
  1450.        (type int16 x y)
  1451.        (type translate translate)
  1452.        (type (or null int32) width)
  1453.        (type index-size size)
  1454.        (values boolean (or null int32))))
  1455.  
  1456. (defun draw-image-glyphs (drawable gcontext x y sequence
  1457.               &key (start 0) end width translate (size :default))
  1458.   ;; An initial font change is allowed from translate, but any subsequent font
  1459.   ;; change or horizontal motion will cause termination (because the protocol
  1460.   ;; doesn't support chaining).  [Alternatively, font changes could be accepted
  1461.   ;; as long as they are accompanied with a width return value, or always
  1462.   ;; accept font changes and call text-width as required.  However, horizontal
  1463.   ;; motion can't really be accepted, due to semantics.]  First result is new
  1464.   ;; start, if end was not reached.  Second result is overall width, if known.
  1465.   (declare (type drawable drawable)
  1466.        (type gcontext gcontext)
  1467.        (type int16 x y)
  1468.        (type sequence sequence)
  1469.        (type array-index start)
  1470.        (type (or null array-index) end)
  1471.        (type (or null int32) width)
  1472.        (type translate translate)
  1473.        (type index-size size)
  1474.        (values (or null array-index) (or null int32))))
  1475.  
  1476. (defun create-colormap (visual window &optional alloc-p)
  1477.   (declare (type card29 visual)
  1478.        (type window window)
  1479.        (type boolean alloc-p)
  1480.        (values colormap)))
  1481.  
  1482. (defun free-colormap (colormap)
  1483.   (declare (type colormap colormap)))
  1484.  
  1485. (defun copy-colormap-and-free (colormap)
  1486.   (declare (type colormap colormap)
  1487.        (values colormap)))
  1488.  
  1489. (defun install-colormap (colormap)
  1490.   (declare (type colormap colormap)))
  1491.  
  1492. (defun uninstall-colormap (colormap)
  1493.   (declare (type colormap colormap)))
  1494.  
  1495. (defun installed-colormaps (window &key (result-type 'list))
  1496.   (declare (type window window)
  1497.        (type type result-type)
  1498.        (values (sequence colormap))))
  1499.  
  1500. (defun alloc-color (colormap color)
  1501.   (declare (type colormap colormap)
  1502.        (type (or stringable color) color)
  1503.        (values pixel screen-color exact-color)))
  1504.  
  1505. (defun alloc-color-cells (colormap colors &key (planes 0) contiguous-p (result-type 'list))
  1506.   (declare (type colormap colormap)
  1507.        (type card16 colors planes)
  1508.        (type boolean contiguous-p)
  1509.        (type type result-type)
  1510.        (values (sequence pixel) (sequence mask))))
  1511.  
  1512. (defun alloc-color-planes (colormap colors
  1513.                &key (reds 0) (greens 0) (blues 0)
  1514.                 contiguous-p (result-type 'list))
  1515.   (declare (type colormap colormap)
  1516.        (type card16 colors reds greens blues)
  1517.        (type boolean contiguous-p)
  1518.        (type type result-type)
  1519.        (values (sequence pixel) red-mask green-mask blue-mask)))
  1520.  
  1521. (defun free-colors (colormap pixels &optional (plane-mask 0))
  1522.   (declare (type colormap colormap)
  1523.        (type (sequence pixel) pixels)
  1524.        (type pixel plane-mask)))
  1525.  
  1526. (defun store-color (colormap pixel spec &key (red-p t) (green-p t) (blue-p t))
  1527.   (declare (type colormap colormap)
  1528.        (type pixel pixel)
  1529.        (type (or stringable color) spec)
  1530.        (type boolean red-p green-p blue-p)))
  1531.  
  1532. (defun store-colors (colormap specs &key (red-p t) (green-p t) (blue-p t))
  1533.   ;; If stringables are specified for colors, it is unspecified whether all
  1534.   ;; stringables are first resolved and then a single StoreColors protocol request is
  1535.   ;; issued, or whether multiple StoreColors protocol requests are issued.
  1536.   (declare (type colormap colormap)
  1537.        (type (repeat-seq (pixel pixel) ((or stringable color) color)) specs)
  1538.        (type boolean red-p green-p blue-p)))
  1539.  
  1540. (defun query-colors (colormap pixels &key (result-type 'list))
  1541.   (declare (type colormap colormap)
  1542.        (type (sequence pixel) pixels)
  1543.        (type type result-type)
  1544.        (values (sequence color))))
  1545.  
  1546. (defun lookup-color (colormap name)
  1547.   (declare (type colormap colormap)
  1548.        (type stringable name)
  1549.        (values screen-color true-color)))
  1550.  
  1551. (defun create-cursor (&key source mask x y foreground background)
  1552.   (declare (type pixmap source)
  1553.        (type (or null pixmap) mask)
  1554.        (type card16 x y)
  1555.        (type color foreground background)
  1556.        (values cursor)))
  1557.  
  1558. (defun create-glyph-cursor (&key source-font source-char mask-font mask-char
  1559.                  foreground background)
  1560.   (declare (type font source-font)
  1561.        (type card16 source-char)
  1562.        (type (or null font) mask-font)
  1563.        (type (or null card16) mask-char)
  1564.        (type color foreground background)
  1565.        (values cursor)))
  1566.  
  1567. (defun free-cursor (cursor)
  1568.   (declare (type cursor cursor)))
  1569.  
  1570. (defun recolor-cursor (cursor foreground background)
  1571.   (declare (type cursor cursor)
  1572.        (type color foreground background)))
  1573.  
  1574. (defun query-best-cursor (width height display)
  1575.   (declare (type card16 width height)
  1576.        (type display display)
  1577.        (values width height)))
  1578.  
  1579. (defun query-best-tile (width height drawable)
  1580.   (declare (type card16 width height)
  1581.        (type drawable drawable)
  1582.        (values width height)))
  1583.  
  1584. (defun query-best-stipple (width height drawable)
  1585.   (declare (type card16 width height)
  1586.        (type drawable drawable)
  1587.        (values width height)))
  1588.  
  1589. (defun query-extension (display name)
  1590.   (declare (type display display)
  1591.        (type stringable name)
  1592.        (values major-opcode first-event first-error)))
  1593.  
  1594. (defun list-extensions (display &key (result-type 'list))
  1595.   (declare (type display display)
  1596.        (type type result-type)
  1597.        (values (sequence string))))
  1598.  
  1599. ;; Should pointer-mapping setf be changed to set-pointer-mapping?
  1600.  
  1601. (defun set-modifier-mapping (display &key shift lock control mod1 mod2 mod3 mod4 mod5)
  1602.   ;; Can signal device-busy.
  1603.   ;; Setf ought to allow multiple values.
  1604.   ;; Returns true for success, nil for failure
  1605.   (declare (type display display)
  1606.        (type (sequence card8) shift lock control mod1 mod2 mod3 mod4 mod5)
  1607.        (values (member :success :busy :failed))))
  1608.  
  1609. (defun modifier-mapping (display)
  1610.   ;; each value is a list of card8s
  1611.   (declare (type display display)
  1612.        (values shift lock control mod1 mod2 mod3 mod4 mod5)))
  1613.  
  1614. ;; Either we will want lots of defconstants for well-known values, or perhaps
  1615. ;; an integer-to-keyword translation function for well-known values.
  1616.  
  1617. (defun change-keyboard-mapping (display keysyms
  1618.                 &key (start 0) end (first-keycode start))
  1619.   ;; start/end give subrange of keysyms
  1620.   ;; first-keycode is the first-keycode to store at
  1621.   (declare (type display display)
  1622.        (type (array * (* *)) keysyms)
  1623.        (type array-index start)
  1624.        (type (or null array-index) end)
  1625.        (type card8 first-keycode)))
  1626.  
  1627. (defun keyboard-mapping (display &key first-keycode start end data)
  1628.   ;; First-keycode specifies which keycode to start at (defaults to
  1629.   ;; min-keycode).  Start specifies where (in result) to put first-keycode
  1630.   ;; (defaults to first-keycode).  (- end start) is the number of keycodes to
  1631.   ;; get (end defaults to (1+ max-keycode)).  If data is specified, the results
  1632.   ;; are put there.
  1633.   (declare (type display display)
  1634.        (type (or null card8) first-keycode)
  1635.        (type (or null array-index) start end)
  1636.        (type (or null (array * (* *))) data)
  1637.        (values (array * (* *)))))
  1638.  
  1639. (defun change-keyboard-control (display &key key-click-percent
  1640.                 bell-percent bell-pitch bell-duration
  1641.                 led led-mode key auto-repeat-mode)
  1642.   (declare (type display display)
  1643.        (type (or null (member :default) int16) key-click-percent
  1644.                            bell-percent bell-pitch bell-duration)
  1645.        (type (or null card8) led key)
  1646.        (type (or null (member :on :off)) led-mode)
  1647.        (type (or null (member :on :off :default)) auto-repeat-mode)))
  1648.  
  1649. (defun keyboard-control (display)
  1650.   (declare (type display display)
  1651.        (values key-click-percent bell-percent bell-pitch bell-duration
  1652.            led-mask global-auto-repeat auto-repeats)))
  1653.  
  1654. (defun bell (display &optional (percent-from-normal 0))
  1655.   ;; It is assumed that an eventual audio extension to X will provide more complete
  1656.   ;; control.
  1657.   (declare (type display display)
  1658.        (type int8 percent-from-normal)))
  1659.  
  1660. (defun pointer-mapping (display &key (result-type 'list))
  1661.   (declare (type display display)
  1662.        (type type result-type)
  1663.        (values (sequence card8))))
  1664.  
  1665. (defsetf pointer-mapping (display) (map)
  1666.   ;; Can signal device-busy.
  1667.   (declare (type display display)
  1668.        (type (sequence card8) map)))
  1669.  
  1670. (defun change-pointer-control (display &key acceleration threshold)
  1671.   ;; Acceleration is rationalized if necessary.
  1672.   (declare (type display display)
  1673.        (type (or null (member :default) number) acceleration)
  1674.        (type (or null (member :default) integer) threshold)))
  1675.  
  1676. (defun pointer-control (display)
  1677.   (declare (type display display)
  1678.        (values acceleration threshold)))
  1679.  
  1680. (defun set-screen-saver (display timeout interval blanking exposures)
  1681.   ;; Setf ought to allow multiple values.
  1682.   ;; Timeout and interval are in seconds, will be rounded to minutes.
  1683.   (declare (type display display)
  1684.        (type (or (member :default) int16) timeout interval)
  1685.        (type (member :yes :no :default) blanking exposures)))
  1686.  
  1687. (defun screen-saver (display)
  1688.   ;; Returns timeout and interval in seconds.
  1689.   (declare (type display display)
  1690.        (values timeout interval blanking exposures)))
  1691.  
  1692. (defun activate-screen-saver (display)
  1693.   (declare (type display display)))
  1694.  
  1695. (defun reset-screen-saver (display)
  1696.   (declare (type display display)))
  1697.  
  1698. (defun add-access-host (display host)
  1699.   ;; A string must be acceptable as a host, but otherwise the possible types for host
  1700.   ;; are not constrained, and will likely be very system dependent.
  1701.   (declare (type display display)))
  1702.  
  1703. (defun remove-access-host (display host)
  1704.   ;; A string must be acceptable as a host, but otherwise the possible types for host
  1705.   ;; are not constrained, and will likely be very system dependent.
  1706.   (declare (type display display)))
  1707.  
  1708. (defun access-hosts (display &key (result-type 'list))
  1709.   ;; The type of host objects returned is not constrained, except that the hosts must
  1710.   ;; be acceptable to add-access-host and remove-access-host.
  1711.   (declare (type display display)
  1712.        (type type result-type)
  1713.        (values (sequence host) enabled-p)))
  1714.  
  1715. (defun access-control (display)
  1716.   ;; setf'able
  1717.   (declare (type display display)
  1718.        (values boolean)))
  1719.  
  1720. (defun close-down-mode (display)
  1721.   ;; setf'able
  1722.   ;; Cached locally in display object.
  1723.   (declare (type display display)
  1724.        (values (member :destroy :retain-permanent :retain-temporary))))
  1725.  
  1726. (defun kill-client (display resource-id)
  1727.   (declare (type display display)
  1728.        (type resource-id resource-id)))
  1729.  
  1730. (defun kill-temporary-clients (display)
  1731.   (declare (type display display)))
  1732.  
  1733. (defun make-event-mask (&rest keys)
  1734.   ;; This is only defined for core events.
  1735.   ;; Useful for constructing event-mask, pointer-event-mask, device-event-mask.
  1736.   (declare (type (list event-mask-class) keys)
  1737.        (values mask32)))
  1738.  
  1739. (defun make-event-keys (event-mask)
  1740.   ;; This is only defined for core events.
  1741.   (declare (type mask32 event-mask)
  1742.        (values (list event-mask-class))))
  1743.  
  1744. (defun make-state-mask (&rest keys)
  1745.   ;; Useful for constructing modifier-mask, state-mask.
  1746.   (declare (type (list state-mask-key) keys)
  1747.        (values mask16)))
  1748.  
  1749. (defun make-state-keys (state-mask)
  1750.   (declare (type mask16 mask)
  1751.        (values (list state-mask-key))))
  1752.  
  1753. (defmacro with-event-queue ((display) &body body)
  1754.   ;; Grants exclusive access to event queue.
  1755.   )
  1756.  
  1757. (defun event-listen (display &optional (timeout 0))
  1758.   (declare (type display display)
  1759.        (type (or null number) timeout))
  1760.   ;; Returns the number of events queued locally, if any, else nil.  Hangs waiting
  1761.   ;; for events, forever if timeout is nil, else for the specified number of seconds.
  1762.   )
  1763.  
  1764. (defun process-event (display &key handler timeout peek-p discard-p (force-output-p t))
  1765.   ;; If force-output-p is true, first invokes display-force-output.  Invokes handler
  1766.   ;; on each queued event until handler returns non-nil, and that returned object is
  1767.   ;; then returned by process-event.  If peek-p is true, then the event is not
  1768.   ;; removed from the queue.  If discard-p is true, then events for which handler
  1769.   ;; returns nil are removed from the queue, otherwise they are left in place.  Hangs
  1770.   ;; until non-nil is generated for some event, or for the specified timeout (in
  1771.   ;; seconds, if given); however, it is acceptable for an implementation to wait only
  1772.   ;; once on network data, and therefore timeout prematurely.  Returns nil on
  1773.   ;; timeout.  If handler is a sequence, it is expected to contain handler functions
  1774.   ;; specific to each event class; the event code is used to index the sequence,
  1775.   ;; fetching the appropriate handler.  The arguments to the handler are described
  1776.   ;; further below using declare-event.  If process-event is invoked recursively, the
  1777.   ;; nested invocation begins with the event after the one currently being processed.
  1778.   (declare (type display display)
  1779.        (type (or (sequence (function (&rest key-vals) t))
  1780.              (function (&rest key-vals) t))
  1781.          handler)
  1782.        (type (or null number) timeout)
  1783.        (type boolean peek-p)))
  1784.  
  1785. (defmacro event-case ((display &key timeout peek-p discard-p (force-output-p t))
  1786.               &body clauses)
  1787.   (declare (arglist (display &key timeout peek-p discard-p force-output-p)
  1788.             (event-or-events ((&rest args) |...|) &body body) |...|))
  1789.   ;; If force-output-p is true, first invokes display-force-output.  Executes the
  1790.   ;; matching clause for each queued event until a clause returns non-nil, and that
  1791.   ;; returned object is then returned by event-case.  If peek-p is true, then the
  1792.   ;; event is not removed from the queue.  If discard-p is true, then events for
  1793.   ;; which the clause returns nil are removed from the queue, otherwise they are left
  1794.   ;; in place.  Hangs until non-nil is generated for some event, or for the specified
  1795.   ;; timeout (in seconds, if given); however, it is acceptable for an implementation
  1796.   ;; to wait only once on network data, and therefore timeout prematurely.  Returns
  1797.   ;; nil on timeout.  In each clause, event-or-events is an event-key or a list of
  1798.   ;; event-keys (but they need not be typed as keywords) or the symbol t or otherwise
  1799.   ;; (but only in the last clause).  The keys are not evaluated, and it is an error
  1800.   ;; for the same key to appear in more than one clause.  Args is the list of event
  1801.   ;; components of interest; corresponding values (if any) are bound to variables
  1802.   ;; with these names (i.e., the args are variable names, not keywords, the keywords
  1803.   ;; are derived from the variable names).  An arg can also be a (keyword var) form,
  1804.   ;; as for keyword args in a lambda lists.  If no t/otherwise clause appears, it is
  1805.   ;; equivalent to having one that returns nil.  If process-event is invoked
  1806.   ;; recursively, the nested invocation begins with the event after the one currently
  1807.   ;; being processed.
  1808.   )
  1809.  
  1810. (defmacro event-cond ((display &key timeout peek-p discard-p (force-output-p t))
  1811.               &body clauses)
  1812.   ;; The clauses of event-cond are of the form:
  1813.   ;; (event-or-events binding-list test-form . body-forms)
  1814.   ;;
  1815.   ;; EVENT-OR-EVENTS    event-key or a list of event-keys (but they
  1816.   ;;            need not be typed as keywords) or the symbol t
  1817.   ;;            or otherwise (but only in the last clause).  If
  1818.   ;;            no t/otherwise clause appears, it is equivalent
  1819.   ;;            to having one that returns nil.  The keys are
  1820.   ;;            not evaluated, and it is an error for the same
  1821.   ;;            key to appear in more than one clause.
  1822.   ;;
  1823.   ;; BINDING-LIST    The list of event components of interest.
  1824.   ;;            corresponding values (if any) are bound to
  1825.   ;;            variables with these names (i.e., the binding-list
  1826.   ;;            has variable names, not keywords, the keywords are
  1827.   ;;            derived from the variable names).  An arg can also
  1828.   ;;            be a (keyword var) form, as for keyword args in a
  1829.   ;;            lambda list.
  1830.   ;;
  1831.   ;; The matching TEST-FORM for each queued event is executed until a
  1832.   ;; clause's test-form returns non-nil.  Then the BODY-FORMS are
  1833.   ;; evaluated, returning the (possibly multiple) values of the last
  1834.   ;; form from event-cond.  If there are no body-forms then, if the
  1835.   ;; test-form is non-nil, the value of the test-form is returned as a
  1836.   ;; single value.
  1837.   ;;
  1838.   ;; Options:
  1839.   ;; FORCE-OUTPUT-P    When true, first invoke display-force-output if no
  1840.   ;;              input is pending.
  1841.   ;;
  1842.   ;; PEEK-P        When true, then the event is not removed from the queue.
  1843.   ;;
  1844.   ;; DISCARD-P        When true, then events for which the clause returns nil
  1845.   ;;             are removed from the queue, otherwise they are left in place.
  1846.   ;;
  1847.   ;; TIMEOUT        If NIL, hang until non-nil is generated for some event's
  1848.   ;;            test-form. Otherwise return NIL after TIMEOUT seconds have
  1849.   ;;            elapsed.
  1850.   ;;
  1851.   (declare (arglist (display &key timeout peek-p discard-p force-output-p)
  1852.            (event-or-events (&rest args) test-form &body body) |...|))
  1853.   )
  1854.  
  1855. (defun discard-current-event (display)
  1856.   (declare (type display display)
  1857.        (values boolean))
  1858.   ;; Discard the current event for DISPLAY.
  1859.   ;; Returns NIL when the event queue is empty, else T.
  1860.   ;; To ensure events aren't ignored, application code should only call
  1861.   ;; this when throwing out of event-case or process-next-event, or from
  1862.   ;; inside even-case, event-cond or process-event when :peek-p is T and
  1863.   ;; :discard-p is NIL.
  1864.  )
  1865.  
  1866. (defmacro declare-event (event-codes &rest declares)
  1867.   ;; Used to indicate the keyword arguments for handler functions in process-event
  1868.   ;; and event-case.  In the declares, an argument listed as (name1 name2) indicates
  1869.   ;; synonyms for the same argument.  All process-event handlers can have
  1870.   ;; (display display), (event-key event-key), and (boolean send-event-p) as keyword
  1871.   ;; arguments, and an event-case clause can also have event-key and send-event-p as
  1872.   ;; arguments.
  1873.   (declare (arglist event-key-or-keys &rest (type &rest keywords))))
  1874.  
  1875. (declare-event (:key-press :key-release :button-press :button-release)
  1876.            (card16 sequence)
  1877.            (window (window event-window) root)
  1878.            ((or null window) child)
  1879.            (boolean same-screen-p)
  1880.            (int16 x y root-x root-y)
  1881.            (card16 state)
  1882.            (card32 time)
  1883.            ;; for key-press and key-release, code is the keycode
  1884.            ;; for button-press and button-release, code is the button number
  1885.            (card8 code))
  1886.  
  1887. (declare-event :motion-notify
  1888.            (card16 sequence)
  1889.            (window (window event-window) root)
  1890.            ((or null window) child)
  1891.            (boolean same-screen-p)
  1892.            (int16 x y root-x root-y)
  1893.            (card16 state)
  1894.            (card32 time)
  1895.            (boolean hint-p))
  1896.  
  1897. (declare-event (:enter-notify :leave-notify)
  1898.            (card16 sequence)
  1899.            (window (window event-window) root)
  1900.            ((or null window) child)
  1901.            (boolean same-screen-p)
  1902.            (int16 x y root-x root-y)
  1903.            (card16 state)
  1904.            (card32 time)
  1905.            ((member :normal :grab :ungrab) mode)
  1906.            ((member :ancestor :virtual :inferior :nonlinear :nonlinear-virtual) kind)
  1907.            (boolean focus-p))
  1908.  
  1909. (declare-event (:focus-in :focus-out)
  1910.            (card16 sequence)
  1911.            (window (window event-window))
  1912.            ((member :normal :while-grabbed :grab :ungrab) mode)
  1913.            ((member :ancestor :virtual :inferior :nonlinear :nonlinear-virtual
  1914.             :pointer :pointer-root :none)
  1915.         kind))
  1916.  
  1917. (declare-event :keymap-notify
  1918.            ((bit-vector 256) keymap))
  1919.  
  1920. (declare-event :exposure
  1921.            (card16 sequence)
  1922.            (window (window event-window))
  1923.            (card16 x y width height count))
  1924.  
  1925. (declare-event :graphics-exposure
  1926.            (card16 sequence)
  1927.            (drawable (drawable event-window))
  1928.            (card16 x y width height count)
  1929.            (card8 major)
  1930.            (card16 minor))
  1931.  
  1932. (declare-event :no-exposure
  1933.            (card16 sequence)
  1934.            (drawable (drawable event-window))
  1935.            (card8 major)
  1936.            (card16 minor))
  1937.  
  1938. (declare-event :visibility-notify
  1939.            (card16 sequence)
  1940.            (window (window event-window))
  1941.            ((member :unobscured :partially-obscured :fully-obscured) state))
  1942.  
  1943. (declare-event :create-notify
  1944.            (card16 sequence)
  1945.            (window window (parent event-window))
  1946.            (int16 x y)
  1947.            (card16 width height border-width)
  1948.            (boolean override-redirect-p))
  1949.  
  1950. (declare-event :destroy-notify
  1951.            (card16 sequence)
  1952.            (window event-window window))
  1953.  
  1954. (declare-event :unmap-notify
  1955.            (card16 sequence)
  1956.            (window event-window window)
  1957.            (boolean configure-p))
  1958.  
  1959. (declare-event :map-notify
  1960.            (card16 sequence)
  1961.            (window event-window window)
  1962.            (boolean override-redirect-p))
  1963.  
  1964. (declare-event :map-request
  1965.            (card16 sequence)
  1966.            (window (parent event-window) window))
  1967.  
  1968. (declare-event :reparent-notify
  1969.            (card16 sequence)
  1970.            (window event-window window parent)
  1971.            (int16 x y)
  1972.            (boolean override-redirect-p))
  1973.  
  1974. (declare-event :configure-notify
  1975.            (card16 sequence)
  1976.            (window event-window window)
  1977.            (int16 x y)
  1978.            (card16 width height border-width)
  1979.            ((or null window) above-sibling)
  1980.            (boolean override-redirect-p))
  1981.  
  1982. (declare-event :gravity-notify
  1983.            (card16 sequence)
  1984.            (window event-window window)
  1985.            (int16 x y))
  1986.  
  1987. (declare-event :resize-request
  1988.            (card16 sequence)
  1989.            (window (window event-window))
  1990.            (card16 width height))
  1991.  
  1992. (declare-event :configure-request
  1993.            (card16 sequence)
  1994.            (window (parent event-window) window)
  1995.            (int16 x y)
  1996.            (card16 width height border-width)
  1997.            ((member :above :below :top-if :bottom-if :opposite) stack-mode)
  1998.            ((or null window) above-sibling)
  1999.            (mask16 value-mask))
  2000.  
  2001. (declare-event :circulate-notify
  2002.            (card16 sequence)
  2003.            (window event-window window)
  2004.            ((member :top :bottom) place))
  2005.  
  2006. (declare-event :circulate-request
  2007.            (card16 sequence)
  2008.            (window (parent event-window) window)
  2009.            ((member :top :bottom) place))
  2010.  
  2011. (declare-event :property-notify
  2012.            (card16 sequence)
  2013.            (window (window event-window))
  2014.            (keyword atom)
  2015.            ((member :new-value :deleted) state)
  2016.            (card32 time))
  2017.  
  2018. (declare-event :selection-clear
  2019.            (card16 sequence)
  2020.            (window (window event-window))
  2021.            (keyword selection)
  2022.            (card32 time))
  2023.  
  2024. (declare-event :selection-request
  2025.            (card16 sequence)
  2026.            (window (window event-window) requestor)
  2027.            (keyword selection target)
  2028.            ((or null keyword) property)
  2029.            (card32 time))
  2030.  
  2031. (declare-event :selection-notify
  2032.            (card16 sequence)
  2033.            (window (window event-window))
  2034.            (keyword selection target)
  2035.            ((or null keyword) property)
  2036.            (card32 time))
  2037.  
  2038. (declare-event :colormap-notify
  2039.            (card16 sequence)
  2040.            (window (window event-window))
  2041.            ((or null colormap) colormap)
  2042.            (boolean new-p installed-p))
  2043.  
  2044. (declare-event :mapping-notify
  2045.            (card16 sequence)
  2046.            ((member :modifier :keyboard :pointer) request)
  2047.            (card8 start count))
  2048.  
  2049. (declare-event :client-message
  2050.            (card16 sequence)
  2051.            (window (window event-window))
  2052.            ((member 8 16 32) format)
  2053.            ((sequence integer) data))
  2054.  
  2055. (defun queue-event (display event-key &rest args &key append-p &allow-other-keys)
  2056.   ;; The event is put at the head of the queue if append-p is nil, else the tail.
  2057.   ;; Additional arguments depend on event-key, and are as specified above with
  2058.   ;; declare-event, except that both resource-ids and resource objects are accepted
  2059.   ;; in the event components.
  2060.   (declare (type display display)
  2061.        (type event-key event-key)
  2062.        (type boolean append-p)))
  2063.  
  2064.  
  2065.  
  2066. ;;; From here on, there has been less coherent review of the interface:
  2067.  
  2068. ;;;-----------------------------------------------------------------------------
  2069. ;;; Window Manager Property functions
  2070.  
  2071. (defun wm-name (window)
  2072.   (declare (type window window)
  2073.        (values string)))
  2074.  
  2075. (defsetf wm-name (window) (name))
  2076.  
  2077. (defun wm-icon-name (window)
  2078.   (declare (type window window)
  2079.        (values string)))
  2080.  
  2081. (defsetf wm-icon-name (window) (name))
  2082.  
  2083. (defun get-wm-class (window)
  2084.   (declare (type window window)
  2085.        (values (or null name-string) (or null class-string))))
  2086.  
  2087. (defun set-wm-class (window resource-name resource-class)
  2088.   (declare (type window window)
  2089.        (type (or null stringable) resource-name resource-class)))
  2090.  
  2091. (defun wm-command (window)
  2092.   ;; Returns a list whose car is a command string and 
  2093.   ;; whose cdr is the list of argument strings.
  2094.   (declare (type window window)
  2095.        (values (list string))))
  2096.  
  2097. (defsetf wm-command (window) (command)
  2098.   ;; Uses PRIN1 to a string-stream with the following bindings:
  2099.   ;; (*print-length* nil) (*print-level* nil) (*print-radix* nil)
  2100.   ;; (*print-base* 10.) (*print-array* t) (*package* (find-package 'lisp))
  2101.   ;; each element of command is seperated with NULL characters.
  2102.   ;; This enables (mapcar #'read-from-string (wm-command window))
  2103.   ;; to recover a lisp command.
  2104.   (declare (type window window)
  2105.        (type (list stringable) command)))
  2106.  
  2107. (defstruct wm-hints
  2108.   (input nil :type (or null (member :off :on)))
  2109.   (initial-state nil :type (or null (member :dont-care :normal :zoom :iconic :inactive)))
  2110.   (icon-pixmap nil :type (or null pixmap))
  2111.   (icon-window nil :type (or null window))
  2112.   (icon-x nil :type (or null card16))
  2113.   (icon-y nil :type (or null card16))
  2114.   (icon-mask nil :type (or null pixmap))
  2115.   (window-group nil :type (or null resource-id))
  2116.   (flags 0 :type card32)    ;; Extension-hook.  Exclusive-Or'ed with the FLAGS field
  2117.   ;; may be extended in the future
  2118.   )
  2119.  
  2120. (defun wm-hints (window)
  2121.   (declare (type window window)
  2122.        (values wm-hints)))
  2123.  
  2124. (defsetf wm-hints (window) (wm-hints))
  2125.  
  2126.  
  2127. (defstruct wm-size-hints
  2128.   ;; Defaulted T to put the burden of remembering these on widget programmers.
  2129.   (user-specified-position-p t :type boolean) ;; True when user specified x y
  2130.   (user-specified-size-p t :type boolean)     ;; True when user specified width height
  2131.   (x nil :type (or null int16))
  2132.   (y nil :type (or null int16))
  2133.   (width nil :type (or null card16))
  2134.   (height nil :type (or null card16))
  2135.   (min-width nil :type (or null card16))
  2136.   (min-height nil :type (or null card16))
  2137.   (max-width nil :type (or null card16))
  2138.   (max-height nil :type (or null card16))
  2139.   (width-inc nil :type (or null card16))
  2140.   (height-inc nil :type (or null card16))
  2141.   (min-aspect nil :type (or null number))
  2142.   (max-aspect nil :type (or null number)))
  2143.  
  2144. (defun wm-normal-hints (window)
  2145.   (declare (type window window)
  2146.        (values wm-size-hints)))
  2147.  
  2148. (defsetf wm-normal-hints (window) (wm-size-hints))
  2149.  
  2150. (defun wm-zoom-hints (window)
  2151.   (declare (type window window)
  2152.        (values wm-size-hints)))
  2153.  
  2154. (defsetf wm-zoom-hints (window) (wm-size-hints))
  2155.  
  2156. ;; ICON-SIZES uses the SIZE-HINTS structure
  2157.  
  2158. (defun icon-sizes (window)
  2159.   (declare (type window window)
  2160.        (values wm-size-hints)))
  2161.   
  2162. (defsetf icon-sizes (window) (wm-size-hints))
  2163.  
  2164. (defun transient-for (window)
  2165.   (declare (type window window)
  2166.        (values window)))
  2167.  
  2168. (defsetf transient-for (window) (transient)
  2169.   (declare (type window window transient)))
  2170.  
  2171. (defun set-standard-properties (window &rest options &key 
  2172.                 name icon-name resource-name resource-class command
  2173.                 hints normal-hints zoom-hints
  2174.                 ;; the following are used for wm-normal-hints
  2175.                 user-specified-position-p
  2176.                 user-specified-size-p
  2177.                 x y width height min-width min-height max-width max-height
  2178.                 width-inc height-inc min-aspect max-aspect
  2179.                 ;; the following are used for wm-hints
  2180.                 input initial-state icon-pixmap icon-window
  2181.                 icon-x icon-y icon-mask window-group)
  2182.   ;; Set properties for WINDOW.
  2183.   (declare (type window window)
  2184.        (type (or null stringable) name icoin-name resource-name resource-class)
  2185.        (type (or null list) command)
  2186.        (type (or null wm-hints) hints)
  2187.        (type (or null wm-size-hints) normal-hints zoom-hints)
  2188.        (type (or null boolean) user-specified-position-p user-specified-size-p)
  2189.        (type (or null int16) x y)
  2190.        (type (or null card16) width height min-width min-height max-width max-height width-inc height-inc)
  2191.        (type (or null number) min-aspect max-aspect)
  2192.        (type (or null (member :off :on)) input)
  2193.        (type (or null (member :dont-care :normal :zoom :iconic :inactive)) initial-state)
  2194.        (type (or null pixmap) icon-pixmap icon-mask)
  2195.        (type (or null window) icon-window)
  2196.        (type (or null card16) icon-x icon-y)
  2197.        (type (or null resource-id) window-group)))
  2198.  
  2199. (defun get-standard-colormap (window property)
  2200.   (declare (type window window)
  2201.        (type (member :rgb_default_map :rgb_best_map :rgb_red_map
  2202.              :rgb_green_map :rgb_blue_map) property)
  2203.        (values colormap base-pixel max-color mult-color)))
  2204.  
  2205. (defun set-standard-colormap (window property colormap base-pixel max-color mult-color)
  2206.   (declare (type window window)
  2207.        (type (member :rgb_default_map :rgb_best_map :rgb_red_map
  2208.              :rgb_green_map :rgb_blue_map) property)
  2209.        (type colormap colormap)
  2210.        (type pixel base-pixel)
  2211.        (type color max-color mult-color)))
  2212.  
  2213. (defun cut-buffer (display &key (buffer 0) (type :string) (result-type 'string)
  2214.                         (transform #'card8->char) (start 0) end)
  2215.   ;; Return the contents of cut-buffer BUFFER
  2216.   (declare (type display display)
  2217.        (type (integer 0 7) buffer)
  2218.        (type xatom type)
  2219.        (type array-index start)
  2220.        (type (or null array-index) end)
  2221.        (type t result-type)            ;a sequence type
  2222.        (type (or null (function (integer) t)) transform)
  2223.        (values sequence type format bytes-after)))
  2224.  
  2225. (defsetf cut-buffer (display buffer &key (type :string) (format 8)
  2226.                  (transform #'char->card8) (start 0) end) (data))
  2227.  
  2228. (defun rotate-cut-buffers (display &optional (delta 1) (careful-p t))
  2229.   ;; Positive rotates left, negative rotates right (opposite of actual
  2230.   ;; protocol request).  When careful-p, ensure all cut-buffer
  2231.   ;; properties are defined, to prevent errors.
  2232.   (declare (type display display)
  2233.        (type int16 delta)
  2234.        (type boolean careful-p)))
  2235.  
  2236. ;;;-----------------------------------------------------------------------------
  2237. ;;; Keycode mapping
  2238.  
  2239. (defun define-keysym-set (set first-keysym last-keysym)
  2240.   ;; Define all keysyms from first-keysym up to and including
  2241.   ;; last-keysym to be in SET (returned from the keysym-set function).
  2242.   ;; Signals an error if the keysym range overlaps an existing set.
  2243.  (declare (type keyword set)
  2244.       (type keysym first-keysym last-keysym)))
  2245.  
  2246. (defun keysym-set (keysym)
  2247.   ;; Return the character code set name of keysym
  2248.   ;; Note that the keyboard set (255) has been broken up into its parts.
  2249.   (declare (type keysym keysym)
  2250.        (values keyword)))
  2251.  
  2252. (defun define-keysym (object keysym &key lowercase translate modifiers mask display)                  
  2253.   ;; Define the translation from keysym/modifiers to a (usually
  2254.   ;; character) object.  ANy previous keysym definition with
  2255.   ;; KEYSYM and MODIFIERS is deleted before adding the new definition.
  2256.   ;;
  2257.   ;; MODIFIERS is either a modifier-mask or list containing intermixed
  2258.   ;; keysyms and state-mask-keys specifying when to use this
  2259.   ;; keysym-translation.  The default is NIL.
  2260.   ;;
  2261.   ;; MASK is either a modifier-mask or list containing intermixed
  2262.   ;; keysyms and state-mask-keys specifying which modifiers to look at
  2263.   ;; (i.e.  modifiers not specified are don't-cares).
  2264.   ;; If mask is :MODIFIERS then the mask is the same as the modifiers
  2265.   ;; (i.e.  modifiers not specified by modifiers are don't cares)
  2266.   ;; The default mask is *default-keysym-translate-mask*
  2267.   ;;
  2268.   ;; If DISPLAY is specified, the translation will be local to DISPLAY,
  2269.   ;; otherwise it will be the default translation for all displays.
  2270.   ;;
  2271.   ;; LOWERCASE is used for uppercase alphabetic keysyms.  The value
  2272.   ;; is the associated lowercase keysym.  This information is used
  2273.   ;; by the keysym-both-case-p predicate (for caps-lock computations)
  2274.   ;; and by the keysym-downcase function.
  2275.   ;;
  2276.   ;; TRANSLATE will be called with parameters (display state OBJECT)
  2277.   ;; when translating KEYSYM and modifiers and mask are satisfied.
  2278.   ;; [e.g (zerop (logxor (logand state (or mask *default-keysym-translate-mask*))
  2279.   ;;                     (or modifiers 0)))
  2280.   ;;      when mask and modifiers aren't lists of keysyms]
  2281.   ;; The default is #'default-keysym-translate
  2282.   ;;
  2283.   (declare (type (or string-char t) object)
  2284.        (type keysym keysym)
  2285.        (type (or null mask16 list) ;; (list (or keysym state-mask-key))
  2286.              modifiers)
  2287.        (type (or null (member :modifiers) mask16 list) ;; (list (or keysym state-mask-key))
  2288.              mask)
  2289.        (type (or null display) display)
  2290.            (type (or null keysym) lowercase)
  2291.        (type (function (display card16 t) t) translate)))
  2292.  
  2293. (defvar *default-keysym-translate-mask*
  2294.     (the (or (member :modifiers) mask16 list)    ; (list (or keysym state-mask-key))
  2295.          (logand #xff (lognot (make-state-mask :lock))))
  2296.   "Default keysym state mask to use during keysym-translation.")
  2297.  
  2298. (defun undefine-keysym (object keysym &key display modifiers &allow-other-keys)                  
  2299.   ;; Undefine the keysym-translation translating KEYSYM to OBJECT with MODIFIERS.
  2300.   ;; If DISPLAY is non-nil, undefine the translation for DISPLAY if it exists.
  2301.   (declare (type (or string-char t) object)
  2302.        (type keysym keysym)
  2303.        (type (or null mask16 list) ;; (list (or keysym state-mask-key))
  2304.              modifiers)
  2305.        (type (or null display) display)))
  2306.  
  2307. (defun default-keysym-translate (display state object)
  2308.   ;; If object is a character, char-bits are set from state.
  2309.   ;; If object is a list, it is an alist with entries:
  2310.   ;; (string-char [modifiers] [mask-modifiers)
  2311.   ;; When MODIFIERS are specified, this character translation
  2312.   ;; will only take effect when the specified modifiers are pressed.
  2313.   ;; MASK-MODIFIERS can be used to specify a set of modifiers to ignore.
  2314.   ;; When MASK-MODIFIERS is missing, all other modifiers are ignored.
  2315.   ;; In ambiguous cases, the most specific translation is used.
  2316.   (declare (type display display)
  2317.        (type card16 state)
  2318.        (type t object)
  2319.        (values t))) ;; Object returned by keycode->character
  2320.    
  2321. (defmacro keysym (keysym &rest bytes)
  2322.   ;; Build a keysym.
  2323.   ;; If KEYSYM is an integer, it is used as the most significant bits of
  2324.   ;; the keysym, and BYTES are used to specify low order bytes. The last
  2325.   ;; parameter is always byte4 of the keysym.  If KEYSYM is not an
  2326.   ;; integer, the keysym associated with KEYSYM is returned.
  2327.   ;;
  2328.   ;; This is a macro and not a function macro to promote compile-time
  2329.   ;; lookup. All arguments are evaluated.
  2330.   (declare (type t keysym)
  2331.        (type (list card8) bytes)
  2332.        (values keysym)))
  2333.  
  2334. (defun character->keysyms (character &optional display)
  2335.   ;; Given a character, return a list of all matching keysyms.
  2336.   ;; If DISPLAY is given, translations specific to DISPLAY are used,
  2337.   ;; otherwise only global translations are used.
  2338.   ;; Implementation dependent function.
  2339.   ;; May be slow [i.e. do a linear search over all known keysyms]
  2340.   (declare (type t character)
  2341.        (type (or null display) display)
  2342.        (values (list keysym))))
  2343.  
  2344. (defun keycode->keysym (display keycode keysym-index)
  2345.   (declare (type display display)
  2346.        (type card8 code)
  2347.        (type card16 state)
  2348.        (type (or null card8) keysym-index)
  2349.        (values keysym)))
  2350.  
  2351. (defun keysym->keycodes (display keysym)
  2352.   ;; Return keycodes for keysym, as multiple values
  2353.   (declare (type display display)
  2354.        (type keysym keysym)
  2355.        (values (or null keycode) (or null keycode) (or null keycode)))
  2356.   )
  2357.  
  2358. (defun keysym->character (display keysym &optional state)
  2359.   ;; Find the character associated with a keysym.
  2360.   ;; STATE is used for adding char-bits to character as follows:
  2361.   ;;    control -> char-control-bit
  2362.   ;;    mod-1 -> char-meta-bit
  2363.   ;;    mod-2 -> char-super-bit
  2364.   ;;    mod-3 -> char-hyper-bit
  2365.   ;; Implementation dependent function.
  2366.   (declare (type display display)
  2367.        (type keysym keysym)
  2368.        (type (or null card16) state)
  2369.        (values (or null character))))
  2370.  
  2371. (defun keycode->character (display keycode state &key keysym-index
  2372.                        (keysym-index-function #'default-keysym-index))
  2373.   ;; keysym-index defaults to the result of keysym-index-function which
  2374.   ;; is called with the following parameters:
  2375.   ;; (char0 state caps-lock-p keysyms-per-keycode)
  2376.   ;; where char0 is the "character" object associated with keysym-index 0 and
  2377.   ;; caps-lock-p is non-nil when the keysym associated with the lock
  2378.   ;; modifier is for caps-lock.
  2379.   ;; STATE is also used for setting char-bits:
  2380.   ;;    control -> char-control-bit
  2381.   ;;    mod-1 -> char-meta-bit
  2382.   ;;    mod-2 -> char-super-bit
  2383.   ;;    mod-3 -> char-hyper-bit
  2384.   ;; Implementation dependent function.
  2385.   (declare (type display display)
  2386.        (type card8 code)
  2387.        (type card16 state)
  2388.        (type (or null card8) keysym-index)
  2389.        (type (or null (function (char0 state caps-lock-p keysyms-per-keycode) card8))
  2390.          keysym-index-function)
  2391.        (values (or null character))))
  2392.  
  2393. (defun default-keysym-index (display keycode state)
  2394.   ;; Returns a keysym-index for use with keycode->character
  2395.   (declare-values card8)
  2396. )
  2397.  
  2398. ;;; default-keysym-index implements the following tables:
  2399. ;;;
  2400. ;;; control shift caps-lock character               character
  2401. ;;;   0       0       0       #\a                      #\8
  2402. ;;;   0       0       1       #\A                      #\8
  2403. ;;;   0       1       0       #\A                      #\*
  2404. ;;;   0       1       1       #\A                      #\*
  2405. ;;;   1       0       0       #\control-A              #\control-8
  2406. ;;;   1       0       1       #\control-A              #\control-8
  2407. ;;;   1       1       0       #\control-shift-a        #\control-*
  2408. ;;;   1       1       1       #\control-shift-a        #\control-*
  2409. ;;;
  2410. ;;; control shift shift-lock character               character
  2411. ;;;   0       0       0       #\a                      #\8
  2412. ;;;   0       0       1       #\A                      #\*
  2413. ;;;   0       1       0       #\A                      #\*
  2414. ;;;   0       1       1       #\A                      #\8
  2415. ;;;   1       0       0       #\control-A              #\control-8
  2416. ;;;   1       0       1       #\control-A              #\control-*
  2417. ;;;   1       1       0       #\control-shift-a        #\control-*
  2418. ;;;   1       1       1       #\control-shift-a        #\control-8
  2419.  
  2420. (defun state-keysymp (display state keysym)
  2421.   ;; Returns T when a modifier key associated with KEYSYM is on in STATE
  2422.   (declare (type display display)
  2423.        (type card16 state)
  2424.        (type keysym keysym)
  2425.        (values boolean)))
  2426.  
  2427. (defun mapping-notify (display request start count)
  2428.   ;; Called on a mapping-notify event to update
  2429.   ;; the keyboard-mapping cache in DISPLAY
  2430.   (declare (type display display)
  2431.        (type (member :modifier :keyboard :pointer) request)
  2432.        (type card8 start count)))
  2433.  
  2434. (defun keysym-in-map-p (display keysym keymap)
  2435.   ;; Returns T if keysym is found in keymap
  2436.   (declare (type display display)
  2437.        (type keysym keysym)
  2438.        (type (bit-vector 256) keymap)
  2439.        (value boolean)))
  2440.  
  2441. (defun character-in-map-p (display character keymap)
  2442.   ;; Implementation dependent function.
  2443.   ;; Returns T if character is found in keymap
  2444.   (declare (type display display)
  2445.        (type t character)
  2446.        (type (bit-vector 256) keymap)
  2447.        (value boolean)))
  2448.  
  2449. ;;;-----------------------------------------------------------------------------
  2450. ;;; Extensions
  2451.  
  2452. (defmacro define-extension (name &key events errors)
  2453.   ;; Define extension NAME with EVENTS and ERRORS.
  2454.   ;; Note: The case of NAME is important.
  2455.   ;; To define the request, Use:
  2456.   ;;     (with-buffer-request (display (extension-opcode ,name)) ,@body)
  2457.   ;;     See the REQUESTS file for lots of examples.
  2458.   ;; To define event handlers, use declare-event.
  2459.   ;; To define error handlers, use declare-error and define-condition.
  2460.   (declare (type stringable name)
  2461.        (type (list symbol) events errors)))
  2462.  
  2463. (defmacro extension-opcode (display name)
  2464.   ;; Returns the major opcode for extension NAME.
  2465.   ;; This is a macro to enable NAME to be interned for fast run-time
  2466.   ;; retrieval. 
  2467.   ;; Note: The case of NAME is important.
  2468.   (declare (type display display)
  2469.        (type stringable name)
  2470.        (values card8)))
  2471.  
  2472. (defmacro define-error (error-key function)
  2473.   ;; Associate a function with ERROR-KEY which will be called with
  2474.   ;; parameters DISPLAY and REPLY-BUFFER and returns a plist of
  2475.   ;; keyword/value pairs which will be passed on to the error handler.
  2476.   ;; A compiler warning is printed when ERROR-KEY is not defined in a
  2477.   ;; preceding DEFINE-EXTENSION.
  2478.   ;; Note: REPLY-BUFFER may used with the READING-EVENT and READ-type
  2479.   ;;       macros for getting error fields. See DECODE-CORE-ERROR for
  2480.   ;        an example.
  2481.   (declare (type symbol error-key)
  2482.        (type function function)))
  2483.  
  2484. ;; All core errors use this, so we make it available to extensions.
  2485. (defun decode-core-error (display event &optional arg)
  2486.   ;; All core errors have the following keyword/argument pairs:
  2487.   ;;    :major integer
  2488.   ;;    :minor integer
  2489.   ;;    :sequence integer
  2490.   ;;    :current-sequence integer
  2491.   ;; In addition, many have an additional argument that comes from the
  2492.   ;; same place in the event, but is named differently.  When the ARG
  2493.   ;; argument is specified, the keyword ARG with card32 value starting
  2494.   ;; at byte 4 of the event is returned with the other keyword/argument
  2495.   ;; pairs.
  2496.   (declare (type display display)
  2497.        (type reply-buffer event)
  2498.        (type (or null keyword) arg)
  2499.        (values keyword/arg-plist)))
  2500.  
  2501. ;; This isn't new, just extended.
  2502. (defmacro declare-event (event-codes &body declares)
  2503.   ;; Used to indicate the keyword arguments for handler functions in
  2504.   ;; process-event and event-case.
  2505.   ;; Generates functions used in SEND-EVENT.
  2506.   ;; A compiler warning is printed when all of EVENT-CODES are not
  2507.   ;; defined by a preceding DEFINE-EXTENSION.
  2508.   ;; See the INPUT file for lots of examples.
  2509.   (declare (type (or keyword (list keywords)) event-codes)
  2510.        (type (alist (field-type symbol) (field-names (list symbol)))
  2511.                  declares)))
  2512.  
  2513. (defmacro define-gcontext-accessor (name &key default set-function copy-function)
  2514.   ;; This will define a new gcontext accessor called NAME.
  2515.   ;; Defines the gcontext-NAME accessor function and its defsetf.
  2516.   ;; Gcontext's will cache DEFAULT-VALUE and the last value SETF'ed when
  2517.   ;; gcontext-cache-p is true.  The NAME keyword will be allowed in
  2518.   ;; CREATE-GCONTEXT, WITH-GCONTEXT, and COPY-GCONTEXT-COMPONENTS.
  2519.   ;; SET-FUNCTION will be called with parameters (GCONTEXT NEW-VALUE)
  2520.   ;; from create-gcontext, and force-gcontext-changes.
  2521.   ;; COPY-FUNCTION will be called with parameters (src-gc dst-gc src-value)
  2522.   ;; from copy-gcontext and copy-gcontext-components.
  2523.   ;; The copy-function defaults to:
  2524.   ;; (lambda (ignore dst-gc value)
  2525.   ;;    (if value
  2526.   ;;        (,set-function dst-gc value)
  2527.   ;;      (error "Can't copy unknown GContext component ~a" ',name)))
  2528.   (declare (type symbol name)
  2529.        (type t default)
  2530.        (type (function (gcontext t) t) set-function) ;; required
  2531.        (type (or null (function (gcontext gcontext t) t))
  2532.          copy-function)))
  2533.  
  2534.  
  2535. ;; To aid extension implementors in attaching additional information to
  2536. ;; clx data structures, the following accessors (with SETF's) are
  2537. ;; defined.  GETF can be used on these to extend the structures.
  2538.  
  2539. display-plist
  2540. screen-plist
  2541. visual-info-plist
  2542. gcontext-plist
  2543. font-plist
  2544. drawable-plist
  2545.  
  2546.  
  2547.  
  2548. ;;; These have had perhaps even less review, and only the images functions are
  2549. ;;; currently implemented.
  2550.  
  2551. ;;; Proposed additions to CLX
  2552. ;;; Add some of the functionality provided by the C XLIB library.
  2553. ;;;
  2554. ;;; LaMott G. Oren, Texas Instruments  10/87
  2555. ;;; 
  2556. ;;; Design Contributors:
  2557. ;;;    Robert W. Scheifler, MIT
  2558.  
  2559. ;;;-----------------------------------------------------------------------------
  2560. ;;; Regions
  2561.  
  2562. ;;; Regions are arbitrary collections of pixels.  This is represented
  2563. ;;; in the region structure as either a list of rectangles or a bitmap.
  2564.  
  2565. (defun make-region (&optional x y width height)
  2566.   ;; With no parameters, returns an empty region
  2567.   ;; If some parameters are given, all must be given.
  2568.   (declare (type (or null int16) x y width height)
  2569.        (values region)))
  2570.  
  2571. (defun region-p (thing))
  2572.  
  2573. (defun copy-region (region))
  2574.  
  2575. (defun region-empty-p (region)
  2576.   (declare (type region region)
  2577.        (values boolean)))
  2578.  
  2579. (defun region-clip-box (region)
  2580.   ;; Returns a region which is the smallest enclosing rectangle
  2581.   ;; enclosing REGION
  2582.   (declare (type region region)
  2583.        (values region)))
  2584.  
  2585. ;; Accessors that return the boundaries of a region
  2586. (defun region-x (region))
  2587. (defun region-y (region))
  2588. (defun region-width (region))
  2589. (defun region-height (region))
  2590.  
  2591. (defsetf region-x (region) (x))
  2592. (defsetf region-y (region) (y))
  2593. ;; Setting a region's X/Y translates the region
  2594.  
  2595. (defun region-intersection (&rest regions)
  2596.   "Returns a region which is the intersection of one or more REGIONS.
  2597. Returns an empty region if the intersection is empty.
  2598. If there are no regions given, return a very large region."
  2599.   (declare (type (list region) regions)
  2600.        (values region)))
  2601.  
  2602. (defun region-union (&rest regions)
  2603.   "Returns a region which is the union of a number of REGIONS
  2604.  (i.e. the smallest region that can contain all the other regions)
  2605.  Returns the empty region if no regions are given."
  2606.   (declare (type (list region) regions)
  2607.        (values region)))
  2608.  
  2609. (defun region-subtract (region subtract)
  2610.   "Returns a region containing the points that are in REGION but not in SUBTRACT"
  2611.   (declare (type region region subtract)
  2612.        (values region)))
  2613.  
  2614. (defun point-in-region-p (region x y)
  2615.   ;; Returns T when X/Y are a point within REGION.
  2616.   (declare (type region region)
  2617.        (type int16 x y)
  2618.        (values boolean)))
  2619.  
  2620. (defun region-equal (a b)
  2621.   ;; Returns T when regions a and b contain the same points.
  2622.   ;; That is, return t when for every X/Y (point-in-region-p a x y)
  2623.   ;; equals (point-in-region-p b x y)
  2624.   (declare (type region a b)
  2625.        (values boolean)))
  2626.  
  2627. (defun subregion-p (large small)
  2628.   "Returns T if SMALL is within LARGE.
  2629.  That is, return T when for every X/Y (point-in-region-p small X Y)
  2630.  implies (point-in-region-p large X Y)."
  2631.   (declare (type region large small)
  2632.        (values boolean)))
  2633.  
  2634. (defun region-intersect-p (a b)
  2635.   "Returns T if A intersects B.
  2636.  That is, return T when there is some point common to regions A and B."
  2637.   (declare (type region a b)
  2638.        (values boolean)))
  2639.  
  2640. (defun map-region (region function &rest args)
  2641.   ;; Calls function with arguments (x y . args) for every point in REGION.
  2642.   (declare (type region region)
  2643.        (type (function x y &rest args) function)))
  2644.  
  2645. ;;   Why isn't it better to augment
  2646. ;;   gcontext-clip-mask to deal with
  2647. ;;       (or null (member :none) pixmap rect-seq region)
  2648. ;;   and force conversions on the caller?
  2649. ;; Good idea.
  2650.  
  2651. ;;(defun gcontext-clip-region (gcontext)
  2652. ;;  ;; If the clip-mask of GCONTEXT is known, return it as a region.
  2653. ;;  (declare (type gcontext gcontext)
  2654. ;;       (values (or null region))))
  2655.  
  2656. ;;(defsetf gcontext-clip-region (gcontext) (region)
  2657. ;;  ;; Set the clip-rectangles or clip-mask for for GCONTEXT to include
  2658. ;;  ;; only the pixels within REGION.
  2659. ;;  (declare (type gcontext gcontext)
  2660. ;;       (type region region)))
  2661.  
  2662. (defun image->region (image)
  2663.   ;; Returns a region containing the 1 bits of a depth-1 image
  2664.   ;; Signals an error if image isn't of depth 1.
  2665.   (declare (type image image)
  2666.        (values region)))
  2667.  
  2668. (defun region->image (region)
  2669.   ;; Returns a depth-1 image containg 1 bits for every pixel in REGION.
  2670.   (declare (type region region)
  2671.        (values image)))
  2672.  
  2673. (defun polygon-region (points &optional (fill-rule :even-odd))
  2674.   (declare (type sequence points) ;(repeat-seq (integer x) (integer y))
  2675.        (type (member :even-odd :winding) fill-rule)
  2676.        (values region)))
  2677.  
  2678. ;;;-----------------------------------------------------------------------------
  2679. ;;; IMAGE functions
  2680.  
  2681.  
  2682. (deftype bitmap () '(array bit (* *)))
  2683. (deftype pixarray () '(array pixel (* *)))
  2684.  
  2685. (defconstant *lisp-byte-lsb-first-p* #+lispm t #-lispm nil
  2686.          "Byte order in pixel arrays")
  2687.  
  2688. (defstruct image
  2689.   ;; Public structure
  2690.   (width 0 :type card16 :read-only t)
  2691.   (height 0 :type card16 :read-only t)
  2692.   (depth 1 :type card8 :read-only t)
  2693.   (plist nil :type list))
  2694.  
  2695. ;; Image-Plist accessors:
  2696. (defun image-name (image))
  2697. (defun image-x-hot (image))
  2698. (defun image-y-hot (image))
  2699. (defun image-red-mask (image))
  2700. (defun image-blue-mask (image))
  2701. (defun image-green-mask (image))
  2702.  
  2703. (defsetf image-name (image) (name))
  2704. (defsetf image-x-hot (image) (x))
  2705. (defsetf image-y-hot (image) (y))
  2706. (defsetf image-red-mask (image) (mask))
  2707. (defsetf image-blue-mask (image) (mask))
  2708. (defsetf image-green-mask (image) (mask))
  2709.  
  2710. (defstruct (image-x (:include image))
  2711.   ;; Use this format for shoveling image data
  2712.   ;; Private structure. Accessors for these NOT exported.
  2713.   (format :z-pixmap :type (member :bitmap :xy-pixmap :z-pixmap))
  2714.   (bytes-per-line 0 :type card16)
  2715.   (scanline-pad 32 :type (member 8 16 32))
  2716.   (bits-per-pixel 0 :type (member 1 4 8 16 24 32))
  2717.   (bit-lsb-first-p nil :type boolean)        ; Bit order
  2718.   (byte-lsb-first-p nil :type boolean)        ; Byte order
  2719.   (data #() :type (array card8 (*))))        ; row-major
  2720.  
  2721. (defstruct (image-xy (:include image))
  2722.   ;; Public structure
  2723.   ;; Use this format for image processing
  2724.   (bitmap-list nil :type (list bitmap)))
  2725.  
  2726. (defstruct (image-z (:include image))
  2727.   ;; Public structure
  2728.   ;; Use this format for image processing
  2729.   (bits-per-pixel 0 :type (member 1 4 8 16 24 32))
  2730.   (pixarray #() :type pixarray))
  2731.  
  2732. (defun create-image (&key (width (required-arg width))
  2733.                   (height (required-arg height))
  2734.              depth data plist name x-hot y-hot
  2735.              red-mask blue-mask green-mask
  2736.              bits-per-pixel format scanline-pad bytes-per-line
  2737.              byte-lsb-first-p bit-lsb-first-p )
  2738.   ;; Returns an image-x image-xy or image-z structure, depending on the
  2739.   ;; type of the :DATA parameter.
  2740.   (declare
  2741.     (type card16 width height)            ; Required
  2742.     (type (or null card8) depth)        ; Defualts to 1
  2743.     (type (or (array card8 (*))            ;Returns image-x
  2744.           (list bitmap)            ;Returns image-xy
  2745.           pixarray) data)            ;Returns image-z
  2746.     (type list plist)
  2747.     (type (or null stringable) name)
  2748.     (type (or null card16) x-hot y-hot)
  2749.     (type (or null pixel) red-mask blue-mask green-mask)
  2750.     (type (or null (member 1 4 8 16 24 32)) bits-per-pixel)
  2751.  
  2752.     ;; The following parameters are ignored for image-xy and image-z:
  2753.     (type (or null (member :bitmap :xy-pixmap :z-pixmap))
  2754.       format)                ; defaults to :z-pixmap
  2755.     (type (or null (member 8 16 32)) scanline-pad)
  2756.     (type (or null card16) bytes-per-line) ;default from width and scanline-pad
  2757.     (type boolean byte-lsb-first-p bit-lsb-first-p)
  2758.     (values image)))
  2759.  
  2760. (defun get-image (drawable &key 
  2761.           (x (required-arg x))
  2762.           (y (required-arg y))
  2763.           (width (required-arg width))
  2764.           (height (required-arg height))
  2765.           plane-mask format result-type)
  2766.   ;; Get an image from the server.
  2767.   ;; Format defaults to :z-pixmap.  Result-Type defaults from Format,
  2768.   ;; image-z for :z-pixmap, and image-xy for :xy-pixmap.
  2769.   ;; Plane-mask defaults to #xFFFFFFFF.
  2770.   ;; Returns an image-x image-xy or image-z structure, depending on the
  2771.   ;; result-type parameter.
  2772.   (declare (type drawable drawable)
  2773.        (type int16 x y) ;; required
  2774.        (type card16 width height) ;; required
  2775.        (type (or null pixel) plane-mask)
  2776.        (type (or null (member :xy-pixmap :z-pixmap)) format)
  2777.        (type (or null (member image-x image-xy image-z)) result-type)
  2778.        (values image)))
  2779.  
  2780. (defun put-image (drawable gcontext image &key
  2781.           (src-x 0) (src-y 0)
  2782.           (x (required-arg x))
  2783.           (y (required-arg y))
  2784.           width height
  2785.           bitmap-p)
  2786.   ;; When BITMAP-P, force format to be :bitmap when depth=1
  2787.   ;; This causes gcontext to supply foreground & background pixels.
  2788.   (declare (type drawable drawable)
  2789.        (type gcontext gcontext)
  2790.        (type image image)
  2791.        (type int16 x y) ;; required
  2792.        (type (or null card16) width height)
  2793.        (type boolean bitmap-p)))
  2794.  
  2795. (defun copy-image (image &key (x 0) (y 0) width height result-type)
  2796.   ;; Copy with optional sub-imaging and format conversion.
  2797.   ;; result-type defaults to (type-of image)
  2798.   (declare (type image image)
  2799.        (type card16 x y)
  2800.        (type (or null card16) width height) ;; Default from image
  2801.        (type (or null (member image-x image-xy image-z)) result-type)
  2802.        (values image)))
  2803.  
  2804. (defun read-bitmap-file (pathname)
  2805.   ;; Creates an image from a C include file in standard X11 format
  2806.   (declare (type (or pathname string stream) pathname)
  2807.        (values image)))
  2808.  
  2809. (defun write-bitmap-file (pathname image &optional name)
  2810.   ;; Writes an image to a C include file in standard X11 format
  2811.   ;; NAME argument used for variable prefixes.  Defaults to "image"
  2812.   (declare (type (or pathname string stream) pathname)
  2813.        (type image image)
  2814.        (type (or null stringable) name)))
  2815.  
  2816. ;;;-----------------------------------------------------------------------------
  2817. ;;; Resource data-base
  2818.  
  2819.  
  2820. (defun make-resource-database ()
  2821.   ;; Returns an empty resource data-base
  2822.   (declare (values resource-database)))
  2823.  
  2824. (defun get-resource (database value-name value-class full-name full-class)
  2825.   ;; Return the value of the resource in DATABASE whose partial name
  2826.   ;; most closely matches (append full-name (list value-name)) and
  2827.   ;;                      (append full-class (list value-class)).
  2828.   (declare (type resource-database database)
  2829.        (type stringable value-name value-class)
  2830.        (type (list stringable) full-name full-class)
  2831.        (values value)))
  2832.  
  2833. (defun add-resource (database name-list value)
  2834.   ;; name-list is a list of either strings or symbols. If a symbol, 
  2835.   ;; case-insensitive comparisons will be used, if a string,
  2836.   ;; case-sensitive comparisons will be used.  The symbol '* or
  2837.   ;; string "*" are used as wildcards, matching anything or nothing.
  2838.   (declare (type resource-database database)
  2839.        (type (list stringable) name-list)
  2840.        (type t value)))
  2841.  
  2842. (defun delete-resource (database name-list)
  2843.   (declare (type resource-database database)
  2844.        (type (list stringable) name-list)))
  2845.  
  2846. (defun map-resource (database function &rest args)
  2847.   ;; Call FUNCTION on each resource in DATABASE.
  2848.   ;; FUNCTION is called with arguments (name-list value . args)
  2849.   (declare (type resource-database database)
  2850.        (type (function ((list stringable) t &rest t) t) function)
  2851.        (values nil)))
  2852.  
  2853. (defun merge-resources (database with-database)
  2854.   (declare (type resource-database database with-database)
  2855.        (values resource-database))
  2856.   (map-resource #'add-resource database with-database)
  2857.   with-database)
  2858.  
  2859. ;; Note: with-input-from-string can be used with read-resources to define
  2860. ;;       default resources in a program file.
  2861.  
  2862. (defun read-resources (database pathname &key key test test-not)
  2863.   ;; Merges resources from a file in standard X11 format with DATABASE.
  2864.   ;; KEY is a function used for converting value-strings, the default is
  2865.   ;; identity.  TEST and TEST-NOT are predicates used for filtering
  2866.   ;; which resources to include in the database.  They are called with
  2867.   ;; the name and results of the KEY function.
  2868.   (declare (type resource-database database)
  2869.        (type (or pathname string stream) pathname)
  2870.        (type (or null (function (string) t)) key)
  2871.        (type (or null (function ((list string) t) boolean))
  2872.                  test test-not)
  2873.        (values resource-database)))
  2874.  
  2875. (defun write-resources (database pathname &key write test test-not)
  2876.   ;; Write resources to PATHNAME in the standard X11 format.
  2877.   ;; WRITE is a function used for writing values, the default is #'princ
  2878.   ;; TEST and TEST-NOT are predicates used for filtering which resources
  2879.   ;; to include in the database.  They are called with the name and value.
  2880.   (declare (type resource-database database)
  2881.        (type (or pathname string stream) pathname)
  2882.        (type (or null (function (string stream) t)) write)
  2883.        (type (or null (function ((list string) t) boolean))
  2884.                  test test-not)))
  2885.  
  2886. (defun wm-resources (database window &key key test test-not)
  2887.   ;; Takes the resources associated with the RESOURCE_MANAGER property
  2888.   ;; of WINDOW (if any) and merges them with DATABASE.
  2889.   ;; KEY is a function used for converting value-strings, the default is
  2890.   ;; identity.  TEST and TEST-NOT are predicates used for filtering
  2891.   ;; which resources to include in the database.  They are called with
  2892.   ;; the name and results of the KEY function.
  2893.   (declare (type resource-database database)
  2894.        (type window window)
  2895.        (type (or null (function (string) t)) key)
  2896.        (type (or null (function ((list string) t) boolean))
  2897.                  test test-not)
  2898.        (values resource-database)))
  2899.  
  2900. (defun set-wm-resources (database window &key write test test-not)
  2901.   ;; Sets the resources associated with the RESOURCE_MANAGER property
  2902.   ;; of WINDOW.
  2903.   ;; WRITE is a function used for writing values, the default is #'princ
  2904.   ;; TEST and TEST-NOT are predicates used for filtering which resources
  2905.   ;; to include in the database.  They are called with the name and value.
  2906.   (declare (type resource-database database)
  2907.        (type window window)
  2908.        (type (or null (function (string stream) t)) write)
  2909.        (type (or null (function ((list string) t) boolean))
  2910.                  test test-not)))
  2911.  
  2912. ;;;-----------------------------------------------------------------------------
  2913. ;;; Shared GContext's
  2914.  
  2915. (defmacro using-gcontext ((var &rest options &key drawable
  2916.                    function plane-mask foreground background
  2917.                    line-width line-style cap-style
  2918.                    join-style fill-style fill-rule arc-mode
  2919.                    tile stipple ts-x ts-y font
  2920.                    subwindow-mode exposures clip-x clip-y
  2921.                    clip-mask clip-ordering dash-offset
  2922.                    dashes)
  2923.               &body body)
  2924.   ;; Equivalent to (let ((var (apply #'make-gcontext options))) ,@body)
  2925.   ;; but more efficient because it uses a gcontext cache associated with
  2926.   ;; drawable's display.
  2927.   )
  2928.  
  2929.  
  2930.  
  2931.  X11 Request Name       CLX Function Name
  2932. -----------------       -----------------
  2933. AllocColor              ALLOC-COLOR
  2934. AllocColorCells         ALLOC-COLOR-CELLS
  2935. AllocColorPlanes        ALLOC-COLOR-PLANES
  2936. AllocNamedColor         ALLOC-COLOR
  2937. AllowEvents             ALLOW-EVENTS
  2938. Bell                    BELL
  2939. ChangeAccessControl     (setf (ACCESS-CONTROL display) boolean)
  2940. ChangeActivePointerGrab CHANGE-ACTIVE-POINTER-GRAB
  2941. ChangeCloseDownMode     (setf (CLOSE-DOWN-MODE display) mode)
  2942. ChangeGC                FORCE-GCONTEXT-CHANGES
  2943.      ;; See WITH-GCONTEXT
  2944.      (setf (gcontext-function gc) boole-constant)
  2945.      (setf (gcontext-plane-mask gc) card32)
  2946.      (setf (gcontext-foreground gc) card32)
  2947.      (setf (gcontext-background gc) card32)
  2948.      (setf (gcontext-line-width gc) card16)
  2949.      (setf (gcontext-line-style gc) keyword)
  2950.      (setf (gcontext-cap-style gc) keyword)
  2951.      (setf (gcontext-join-style gc) keyword)
  2952.      (setf (gcontext-fill-style gc) keyword)
  2953.      (setf (gcontext-fill-rule gc) keyword)
  2954.      (setf (gcontext-tile gc) pixmap)
  2955.      (setf (gcontext-stipple gc) pixmap)
  2956.      (setf (gcontext-ts-x gc) int16) ;; Tile-Stipple-X-origin
  2957.      (setf (gcontext-ts-y gc) int16) ;; Tile-Stipple-Y-origin
  2958.      (setf (gcontext-font gc &optional metrics-p) font)
  2959.      (setf (gcontext-subwindow-mode gc) keyword)
  2960.      (setf (gcontext-exposures gc) (member :on :off))
  2961.      (setf (gcontext-clip-x gc) int16)
  2962.      (setf (gcontext-clip-y gc) int16)
  2963.      (setf (gcontext-clip-mask gc &optional ordering)
  2964.        (or (member :none) pixmap rect-seq))
  2965.      (setf (gcontext-dash-offset gc) card16)
  2966.      (setf (gcontext-dashes gc) (or card8 sequence))
  2967.      (setf (gcontext-arc-mode gc) (member :chord :pie-slice))
  2968.      (setf (gcontext-clip-ordering gc) keyword)
  2969.  
  2970. ChangeHosts             ADD-ACCESS-HOST
  2971. ChangeHosts             REMOVE-ACCESS-HOST
  2972. ChangeKeyboardControl   CHANGE-KEYBOARD-CONTROL
  2973. ChangePointerControl    CHANGE-POINTER-CONTROL
  2974. ChangeProperty          CHANGE-PROPERTY
  2975. ChangeSaveSet           REMOVE-FROM-SAVE-SET
  2976. ChangeSaveSet           ADD-TO-SAVE-SET
  2977. ChangeWindowAttributes
  2978.      ;; See WITH-STATE
  2979.      (setf (window-background window) value)
  2980.      (setf (window-border window) value)
  2981.      (setf (window-bit-gravity window) value)
  2982.      (setf (window-gravity window) value)
  2983.      (setf (window-backing-store window) value)
  2984.      (setf (window-backing-planes window) value)
  2985.      (setf (window-backing-pixel window) value)
  2986.      (setf (window-override-redirect window) value)
  2987.      (setf (window-save-under window) value)
  2988.      (setf (window-colormap window) value)
  2989.      (setf (window-cursor window) value)
  2990.      (setf (window-event-mask window) value)
  2991.      (setf (window-do-not-propagate-mask window) value)
  2992.  
  2993. CirculateWindow         CIRCULATE-WINDOW-DOWN
  2994. CirculateWindow         CIRCULATE-WINDOW-UP
  2995. ClearToBackground       CLEAR-AREA
  2996. CloseFont               CLOSE-FONT
  2997. ConfigureWindow
  2998.      ;; See WITH-STATE
  2999.      (setf (drawable-x drawable) integer)
  3000.      (setf (drawable-y drawable) integer)
  3001.      (setf (drawable-width drawable) integer)
  3002.      (setf (drawable-height drawable) integer)
  3003.      (setf (drawable-depth drawable) integer)
  3004.      (setf (drawable-border-width drawable) integer)
  3005.      (setf (window-priority window &optional sibling) integer)
  3006.  
  3007. ConvertSelection        CONVERT-SELECTION
  3008. CopyArea                COPY-AREA
  3009. CopyColormapAndFree     COPY-COLORMAP-AND-FREE
  3010. CopyGC                  COPY-GCONTEXT
  3011. CopyGC                  COPY-GCONTEXT-COMPONENTS
  3012. CopyPlane               COPY-PLANE
  3013. CreateColormap          CREATE-COLORMAP
  3014. CreateCursor            CREATE-CURSOR
  3015. CreateGC                CREATE-GCONTEXT
  3016. CreateGlyphCursor       CREATE-GLYPH-CURSOR
  3017. CreatePixmap            CREATE-PIXMAP
  3018. CreateWindow            CREATE-WINDOW
  3019. DeleteProperty          DELETE-PROPERTY
  3020. DestroySubwindows       DESTROY-SUBWINDOWS
  3021. DestroyWindow           DESTROY-WINDOW
  3022. FillPoly                DRAW-LINES
  3023. ForceScreenSaver        RESET-SCREEN-SAVER
  3024. ForceScreenSaver        ACTIVATE-SCREEN-SAVER
  3025. FreeColormap            FREE-COLORMAP
  3026. FreeColors              FREE-COLORS
  3027. FreeCursor              FREE-CURSOR
  3028. FreeGC                  FREE-GCONTEXT
  3029. FreePixmap              FREE-PIXMAP
  3030. GetAtomName             ATOM-NAME
  3031. GetFontPath             FONT-PATH
  3032. GetGeometry             ;; See WITH-STATE
  3033.                         DRAWABLE-ROOT
  3034.                         DRAWABLE-X
  3035.                         DRAWABLE-Y
  3036.                         DRAWABLE-WIDTH
  3037.                         DRAWABLE-HEIGHT
  3038.                         DRAWABLE-DEPTH
  3039.                         DRAWABLE-BORDER-WIDTH
  3040.  
  3041. GetImage                GET-RAW-IMAGE
  3042. GetInputFocus           INPUT-FOCUS
  3043. GetKeyboardControl      KEYBOARD-CONTROL
  3044. GetKeyboardMapping      KEYBOARD-MAPPING
  3045. GetModifierMapping      MODIFIER-MAPPING
  3046. GetMotionEvents         MOTION-EVENTS
  3047. GetPointerControl       POINTER-CONTROL
  3048. GetPointerMapping       POINTER-MAPPING
  3049. GetProperty             GET-PROPERTY
  3050. GetScreenSaver          SCREEN-SAVER
  3051. GetSelectionOwner       SELECTION-OWNER
  3052. GetWindowAttributes     ;; See WITH-STATE
  3053.                         WINDOW-VISUAL
  3054.                         WINDOW-CLASS
  3055.                         WINDOW-BIT-GRAVITY
  3056.                         WINDOW-GRAVITY
  3057.                         WINDOW-BACKING-STORE
  3058.                         WINDOW-BACKING-PLANES
  3059.                         WINDOW-BACKING-PIXEL
  3060.                         WINDOW-SAVE-UNDER
  3061.                         WINDOW-OVERRIDE-REDIRECT
  3062.                         WINDOW-EVENT-MASK
  3063.                         WINDOW-DO-NOT-PROPAGATE-MASK
  3064.                         WINDOW-COLORMAP
  3065.                         WINDOW-COLORMAP-INSTALLED-P
  3066.                         WINDOW-ALL-EVENT-MASKS
  3067.                         WINDOW-MAP-STATE
  3068.  
  3069. GrabButton              GRAB-BUTTON
  3070. GrabKey                 GRAB-KEY
  3071. GrabKeyboard            GRAB-KEYBOARD
  3072. GrabPointer             GRAB-POINTER
  3073. GrabServer              GRAB-SERVER
  3074. ImageText16             DRAW-IMAGE-GLYPHS
  3075. ImageText16             DRAW-IMAGE-GLYPH
  3076. ImageText8              DRAW-IMAGE-GLYPHS
  3077. InstallColormap         INSTALL-COLORMAP
  3078. InternAtom              FIND-ATOM
  3079. InternAtom              INTERN-ATOM
  3080. KillClient              KILL-TEMPORARY-CLIENTS
  3081. KillClient              KILL-CLIENT
  3082. ListExtensions          LIST-EXTENSIONS
  3083. ListFonts               LIST-FONT-NAMES
  3084. ListFontsWithInfo       LIST-FONTS
  3085. ListHosts               ACCESS-CONTROL
  3086. ListHosts               ACCESS-HOSTS
  3087. ListInstalledColormaps  INSTALLED-COLORMAPS
  3088. ListProperties          LIST-PROPERTIES
  3089. LookupColor             LOOKUP-COLOR
  3090. MapSubwindows           MAP-SUBWINDOWS
  3091. MapWindow               MAP-WINDOW
  3092. OpenFont                OPEN-FONT
  3093. PolyArc                 DRAW-ARC
  3094. PolyArc                 DRAW-ARCS
  3095. PolyFillArc             DRAW-ARC
  3096. PolyFillArc             DRAW-ARCS
  3097. PolyFillRectangle       DRAW-RECTANGLE
  3098. PolyFillRectangle       DRAW-RECTANGLES
  3099. PolyLine                DRAW-LINE
  3100. PolyLine                DRAW-LINES
  3101. PolyPoint               DRAW-POINT
  3102. PolyPoint               DRAW-POINTS
  3103. PolyRectangle           DRAW-RECTANGLE
  3104. PolyRectangle           DRAW-RECTANGLES
  3105. PolySegment             DRAW-SEGMENTS
  3106. PolyText16              DRAW-GLYPH
  3107. PolyText16              DRAW-GLYPHS
  3108. PolyText8               DRAW-GLYPHS
  3109. PutImage                PUT-RAW-IMAGE
  3110. QueryBestSize           QUERY-BEST-CURSOR
  3111. QueryBestSize           QUERY-BEST-STIPPLE
  3112. QueryBestSize           QUERY-BEST-TILE
  3113. QueryColors             QUERY-COLORS
  3114. QueryExtension          QUERY-EXTENSION
  3115. QueryFont               FONT-NAME
  3116.                         FONT-NAME
  3117.                         FONT-DIRECTION
  3118.                         FONT-MIN-CHAR
  3119.                         FONT-MAX-CHAR
  3120.                         FONT-MIN-BYTE1
  3121.                         FONT-MAX-BYTE1
  3122.                         FONT-MIN-BYTE2
  3123.                         FONT-MAX-BYTE2
  3124.                         FONT-ALL-CHARS-EXIST-P
  3125.                         FONT-DEFAULT-CHAR
  3126.                         FONT-ASCENT
  3127.                         FONT-DESCENT
  3128.                         FONT-PROPERTIES
  3129.                         FONT-PROPERTY
  3130.      
  3131.                         CHAR-LEFT-BEARING
  3132.                         CHAR-RIGHT-BEARING
  3133.                         CHAR-WIDTH
  3134.                         CHAR-ASCENT
  3135.                         CHAR-DESCENT
  3136.                         CHAR-ATTRIBUTES
  3137.      
  3138.                         MIN-CHAR-LEFT-BEARING
  3139.                         MIN-CHAR-RIGHT-BEARING
  3140.                         MIN-CHAR-WIDTH
  3141.                         MIN-CHAR-ASCENT
  3142.                         MIN-CHAR-DESCENT
  3143.                         MIN-CHAR-ATTRIBUTES
  3144.      
  3145.                         MAX-CHAR-LEFT-BEARING
  3146.                         MAX-CHAR-RIGHT-BEARING
  3147.                         MAX-CHAR-WIDTH
  3148.                         MAX-CHAR-ASCENT
  3149.                         MAX-CHAR-DESCENT
  3150.                         MAX-CHAR-ATTRIBUTES
  3151.  
  3152. QueryKeymap             QUERY-KEYMAP
  3153. QueryPointer            GLOBAL-POINTER-POSITION
  3154. QueryPointer            POINTER-POSITION
  3155. QueryPointer            QUERY-POINTER
  3156. QueryTextExtents        TEXT-EXTENTS
  3157. QueryTextExtents        TEXT-WIDTH
  3158. QueryTree               QUERY-TREE
  3159. RecolorCursor           RECOLOR-CURSOR
  3160. ReparentWindow          REPARENT-WINDOW
  3161. RotateProperties        ROTATE-PROPERTIES
  3162. SendEvent               SEND-EVENT
  3163. SetClipRectangles       FORCE-GCONTEXT-CHANGES
  3164.      ;; See WITH-GCONTEXT
  3165.      (setf (gcontext-clip-x gc) int16)
  3166.      (setf (gcontext-clip-y gc) int16)
  3167.      (setf (gcontext-clip-mask gc &optional ordering)
  3168.        (or (member :none) pixmap rect-seq))
  3169.      (setf (gcontext-clip-ordering gc) keyword)
  3170.  
  3171. SetDashes               FORCE-GCONTEXT-CHANGES
  3172.      ;; See WITH-GCONTEXT
  3173.      (setf (gcontext-dash-offset gc) card16)
  3174.      (setf (gcontext-dashes gc) (or card8 sequence))
  3175.  
  3176. SetFontPath
  3177.      (setf (font-path font) paths)
  3178.     Where paths is (type (sequence (or string pathname)))
  3179.  
  3180. SetInputFocus           SET-INPUT-FOCUS
  3181. SetKeyboardMapping      CHANGE-KEYBOARD-MAPPING
  3182. SetModifierMapping      SET-MODIFIER-MAPPING
  3183. SetPointerMapping       SET-POINTER-MAPPING
  3184. SetScreenSaver          SET-SCREEN-SAVER
  3185. SetSelectionOwner       SET-SELECTION-OWNER
  3186. StoreColors             STORE-COLOR
  3187. StoreColors             STORE-COLORS
  3188. StoreNamedColor         STORE-COLOR
  3189. StoreNamedColor         STORE-COLORS
  3190. TranslateCoords         TRANSLATE-COORDINATES
  3191. UngrabButton            UNGRAB-BUTTON
  3192. UngrabKey               UNGRAB-KEY
  3193. UngrabKeyboard          UNGRAB-KEYBOARD
  3194. UngrabPointer           UNGRAB-POINTER
  3195. UngrabServer            UNGRAB-SERVER
  3196. UninstallColormap       UNINSTALL-COLORMAP
  3197. UnmapSubwindows         UNMAP-SUBWINDOWS
  3198. UnmapWindow             UNMAP-WINDOW
  3199. WarpPointer             WARP-POINTER
  3200. WarpPointer             WARP-POINTER-IF-INSIDE
  3201. WarpPointer             WARP-POINTER-RELATIVE
  3202. WarpPointer             WARP-POINTER-RELATIVE-IF-INSIDE
  3203.  
  3204.  
  3205.  
  3206.  X11 Request Name       CLX Function Name
  3207. -----------------       -----------------
  3208. ListHosts               ACCESS-CONTROL
  3209. ListHosts               ACCESS-HOSTS
  3210. ForceScreenSaver        ACTIVATE-SCREEN-SAVER
  3211. ChangeHosts             ADD-ACCESS-HOST
  3212. ChangeSaveSet           ADD-TO-SAVE-SET
  3213. AllocColor              ALLOC-COLOR
  3214. AllocNamedColor         ALLOC-COLOR
  3215. AllocColorCells         ALLOC-COLOR-CELLS
  3216. AllocColorPlanes        ALLOC-COLOR-PLANES
  3217. AllowEvents             ALLOW-EVENTS
  3218. GetAtomName             ATOM-NAME
  3219. Bell                    BELL
  3220. ChangeActivePointerGrab CHANGE-ACTIVE-POINTER-GRAB
  3221. ChangeKeyboardControl   CHANGE-KEYBOARD-CONTROL
  3222. SetKeyboardMapping      CHANGE-KEYBOARD-MAPPING
  3223. ChangePointerControl    CHANGE-POINTER-CONTROL
  3224. ChangeProperty          CHANGE-PROPERTY
  3225. QueryFont               CHAR-ASCENT
  3226. QueryFont               CHAR-ATTRIBUTES
  3227. QueryFont               CHAR-DESCENT
  3228. QueryFont               CHAR-LEFT-BEARING
  3229. QueryFont               CHAR-RIGHT-BEARING
  3230. QueryFont               CHAR-WIDTH
  3231. CirculateWindow         CIRCULATE-WINDOW-DOWN
  3232. CirculateWindow         CIRCULATE-WINDOW-UP
  3233. ClearToBackground       CLEAR-AREA
  3234. CloseFont               CLOSE-FONT
  3235. ConvertSelection        CONVERT-SELECTION
  3236. CopyArea                COPY-AREA
  3237. CopyColormapAndFree     COPY-COLORMAP-AND-FREE
  3238. CopyGC                  COPY-GCONTEXT
  3239. CopyGC                  COPY-GCONTEXT-COMPONENTS
  3240. CopyPlane               COPY-PLANE
  3241. CreateColormap          CREATE-COLORMAP
  3242. CreateCursor            CREATE-CURSOR
  3243. CreateGC                CREATE-GCONTEXT
  3244. CreateGlyphCursor       CREATE-GLYPH-CURSOR
  3245. CreatePixmap            CREATE-PIXMAP
  3246. CreateWindow            CREATE-WINDOW
  3247. DeleteProperty          DELETE-PROPERTY
  3248. DestroySubwindows       DESTROY-SUBWINDOWS
  3249. DestroyWindow           DESTROY-WINDOW
  3250. PolyArc                 DRAW-ARC
  3251. PolyArc                 DRAW-ARCS
  3252. PolyText16              DRAW-GLYPH
  3253. PolyText16              DRAW-GLYPHS
  3254. PolyText8               DRAW-GLYPHS
  3255. ImageText16             DRAW-IMAGE-GLYPH
  3256. ImageText16             DRAW-IMAGE-GLYPHS
  3257. ImageText8              DRAW-IMAGE-GLYPHS
  3258. PolyLine                DRAW-LINE
  3259. PolyLine                DRAW-LINES
  3260. PolyPoint               DRAW-POINT
  3261. PolyPoint               DRAW-POINTS
  3262. PolyFillRectangle       DRAW-RECTANGLE
  3263. PolyRectangle           DRAW-RECTANGLE
  3264. PolyFillRectangle       DRAW-RECTANGLES
  3265. PolyRectangle           DRAW-RECTANGLES
  3266. PolySegment             DRAW-SEGMENTS
  3267. GetGeometry             DRAWABLE-BORDER-WIDTH
  3268. GetGeometry             DRAWABLE-DEPTH
  3269. GetGeometry             DRAWABLE-HEIGHT
  3270. GetGeometry             DRAWABLE-ROOT
  3271. GetGeometry             DRAWABLE-WIDTH
  3272. GetGeometry             DRAWABLE-X
  3273. GetGeometry             DRAWABLE-Y
  3274. FillPoly                FILL-POLYGON
  3275. InternAtom              FIND-ATOM
  3276. QueryFont               FONT-ALL-CHARS-EXIST-P
  3277. QueryFont               FONT-ASCENT
  3278. QueryFont               FONT-DEFAULT-CHAR
  3279. QueryFont               FONT-DESCENT
  3280. QueryFont               FONT-DIRECTION
  3281. QueryFont               FONT-MAX-BYTE1
  3282. QueryFont               FONT-MAX-BYTE2
  3283. QueryFont               FONT-MAX-CHAR
  3284. QueryFont               FONT-MIN-BYTE1
  3285. QueryFont               FONT-MIN-BYTE2
  3286. QueryFont               FONT-MIN-CHAR
  3287. QueryFont               FONT-NAME
  3288. QueryFont               FONT-NAME
  3289. GetFontPath             FONT-PATH
  3290. QueryFont               FONT-PROPERTIES
  3291. QueryFont               FONT-PROPERTY
  3292. ChangeGC                FORCE-GCONTEXT-CHANGES
  3293. SetClipRectangles       FORCE-GCONTEXT-CHANGES
  3294. SetDashes               FORCE-GCONTEXT-CHANGES
  3295. FreeColormap            FREE-COLORMAP
  3296. FreeColors              FREE-COLORS
  3297. FreeCursor              FREE-CURSOR
  3298. FreeGC                  FREE-GCONTEXT
  3299. FreePixmap              FREE-PIXMAP
  3300. GetProperty             GET-PROPERTY
  3301. GetImage                GET-RAW-IMAGE
  3302. QueryPointer            GLOBAL-POINTER-POSITION
  3303. GrabButton              GRAB-BUTTON
  3304. GrabKey                 GRAB-KEY
  3305. GrabKeyboard            GRAB-KEYBOARD
  3306. GrabPointer             GRAB-POINTER
  3307. GrabServer              GRAB-SERVER
  3308. GrabServer              WITH-SERVER-GRABBED
  3309. GetInputFocus           INPUT-FOCUS
  3310. InstallColormap         INSTALL-COLORMAP
  3311. ListInstalledColormaps  INSTALLED-COLORMAPS
  3312. InternAtom              INTERN-ATOM
  3313. GetKeyboardControl      KEYBOARD-CONTROL
  3314. GetKeyboardMapping      KEYBOARD-MAPPING
  3315. KillClient              KILL-CLIENT
  3316. KillClient              KILL-TEMPORARY-CLIENTS
  3317. ListExtensions          LIST-EXTENSIONS
  3318. ListFonts               LIST-FONT-NAMES
  3319. ListFontsWithInfo       LIST-FONTS
  3320. ListProperties          LIST-PROPERTIES
  3321. LookupColor             LOOKUP-COLOR
  3322. MapSubwindows           MAP-SUBWINDOWS
  3323. MapWindow               MAP-WINDOW
  3324. QueryFont               MAX-CHAR-ASCENT
  3325. QueryFont               MAX-CHAR-ATTRIBUTES
  3326. QueryFont               MAX-CHAR-DESCENT
  3327. QueryFont               MAX-CHAR-LEFT-BEARING
  3328. QueryFont               MAX-CHAR-RIGHT-BEARING
  3329. QueryFont               MAX-CHAR-WIDTH
  3330. QueryFont               MIN-CHAR-ASCENT
  3331. QueryFont               MIN-CHAR-ATTRIBUTES
  3332. QueryFont               MIN-CHAR-DESCENT
  3333. QueryFont               MIN-CHAR-LEFT-BEARING
  3334. QueryFont               MIN-CHAR-RIGHT-BEARING
  3335. QueryFont               MIN-CHAR-WIDTH
  3336. GetModifierMapping      MODIFIER-MAPPING
  3337. GetMotionEvents         MOTION-EVENTS
  3338. OpenFont                OPEN-FONT
  3339. GetPointerControl       POINTER-CONTROL
  3340. GetPointerMapping       POINTER-MAPPING
  3341. QueryPointer            POINTER-POSITION
  3342. PutImage                PUT-RAW-IMAGE
  3343. QueryBestSize           QUERY-BEST-CURSOR
  3344. QueryBestSize           QUERY-BEST-STIPPLE
  3345. QueryBestSize           QUERY-BEST-TILE
  3346. QueryColors             QUERY-COLORS
  3347. QueryExtension          QUERY-EXTENSION
  3348. QueryKeymap             QUERY-KEYMAP
  3349. QueryPointer            QUERY-POINTER
  3350. QueryTree               QUERY-TREE
  3351. RecolorCursor           RECOLOR-CURSOR
  3352. ChangeHosts             REMOVE-ACCESS-HOST
  3353. ChangeSaveSet           REMOVE-FROM-SAVE-SET
  3354. ReparentWindow          REPARENT-WINDOW
  3355. ForceScreenSaver        RESET-SCREEN-SAVER
  3356. RotateProperties        ROTATE-PROPERTIES
  3357. GetScreenSaver          SCREEN-SAVER
  3358. GetSelectionOwner       SELECTION-OWNER
  3359. SendEvent               SEND-EVENT
  3360. ChangeAccessControl     SET-ACCESS-CONTROL
  3361. ChangeCloseDownMode     SET-CLOSE-DOWN-MODE
  3362. SetInputFocus           SET-INPUT-FOCUS
  3363. SetModifierMapping      SET-MODIFIER-MAPPING
  3364. SetPointerMapping       SET-POINTER-MAPPING
  3365. SetScreenSaver          SET-SCREEN-SAVER
  3366. SetSelectionOwner       SET-SELECTION-OWNER
  3367. StoreColors             STORE-COLOR
  3368. StoreColors             STORE-COLORS
  3369. StoreNamedColor         STORE-COLOR
  3370. StoreNamedColor         STORE-COLORS
  3371. QueryTextExtents        TEXT-EXTENTS
  3372. QueryTextExtents        TEXT-WIDTH
  3373. TranslateCoords         TRANSLATE-COORDINATES
  3374. UngrabButton            UNGRAB-BUTTON
  3375. UngrabKey               UNGRAB-KEY
  3376. UngrabKeyboard          UNGRAB-KEYBOARD
  3377. UngrabPointer           UNGRAB-POINTER
  3378. UngrabServer            UNGRAB-SERVER
  3379. UngrabServer            WITH-SERVER-GRABBED
  3380. UninstallColormap       UNINSTALL-COLORMAP
  3381. UnmapSubwindows         UNMAP-SUBWINDOWS
  3382. UnmapWindow             UNMAP-WINDOW
  3383. WarpPointer             WARP-POINTER
  3384. WarpPointer             WARP-POINTER-IF-INSIDE
  3385. WarpPointer             WARP-POINTER-RELATIVE
  3386. WarpPointer             WARP-POINTER-RELATIVE-IF-INSIDE
  3387. GetWindowAttributes     WINDOW-ALL-EVENT-MASKS
  3388. GetWindowAttributes     WINDOW-BACKING-PIXEL
  3389. GetWindowAttributes     WINDOW-BACKING-PLANES
  3390. GetWindowAttributes     WINDOW-BACKING-STORE
  3391. GetWindowAttributes     WINDOW-BIT-GRAVITY
  3392. GetWindowAttributes     WINDOW-CLASS
  3393. GetWindowAttributes     WINDOW-COLORMAP
  3394. GetWindowAttributes     WINDOW-COLORMAP-INSTALLED-P
  3395. GetWindowAttributes     WINDOW-DO-NOT-PROPAGATE-MASK
  3396. GetWindowAttributes     WINDOW-EVENT-MASK
  3397. GetWindowAttributes     WINDOW-GRAVITY
  3398. GetWindowAttributes     WINDOW-MAP-STATE
  3399. GetWindowAttributes     WINDOW-OVERRIDE-REDIRECT
  3400. GetWindowAttributes     WINDOW-SAVE-UNDER
  3401. GetWindowAttributes     WINDOW-VISUAL
  3402.  
  3403. ConfigureWindow         (SETF (DRAWABLE-BORDER-WIDTH DRAWABLE) INTEGER)
  3404. ConfigureWindow         (SETF (DRAWABLE-DEPTH DRAWABLE) INTEGER)
  3405. ConfigureWindow         (SETF (DRAWABLE-HEIGHT DRAWABLE) INTEGER)
  3406. ConfigureWindow         (SETF (DRAWABLE-WIDTH DRAWABLE) INTEGER)
  3407. ConfigureWindow         (SETF (DRAWABLE-X DRAWABLE) INTEGER)
  3408. ConfigureWindow         (SETF (DRAWABLE-Y DRAWABLE) INTEGER)
  3409. SetFontPath             (SETF (FONT-PATH FONT) PATHS)
  3410. ChangeGC                (SETF (GCONTEXT-ARC-MODE GC) (MEMBER CHORD PIE-SLICE))
  3411. ChangeGC                (SETF (GCONTEXT-BACKGROUND GC) CARD32)
  3412. ChangeGC                (SETF (GCONTEXT-CAP-STYLE GC) KEYWORD)
  3413. SetClipRectangles       (SETF (GCONTEXT-CLIP-MASK GC &OPTIONAL ORDERING)
  3414.                           (OR (MEMBER NONE) PIXMAP RECT-SEQ))
  3415. SetClipRectangles       (SETF (GCONTEXT-CLIP-ORDERING GC) KEYWORD)
  3416. SetClipRectangles       (SETF (GCONTEXT-CLIP-X GC) INT16)
  3417. SetClipRectangles       (SETF (GCONTEXT-CLIP-Y GC) INT16)
  3418. SetDashes               (SETF (GCONTEXT-DASH-OFFSET GC) CARD16)
  3419. SetDashes               (SETF (GCONTEXT-DASHES GC) (OR CARD8 SEQUENCE))
  3420. ChangeGC                (SETF (GCONTEXT-EXPOSURES GC) (MEMBER ON OFF))
  3421. ChangeGC                (SETF (GCONTEXT-FILL-RULE GC) KEYWORD)
  3422. ChangeGC                (SETF (GCONTEXT-FILL-STYLE GC) KEYWORD)
  3423. ChangeGC                (SETF (GCONTEXT-FONT GC &OPTIONAL METRICS-P) FONT)
  3424. ChangeGC                (SETF (GCONTEXT-FOREGROUND GC) CARD32)
  3425. ChangeGC                (SETF (GCONTEXT-FUNCTION GC) BOOLE-CONSTANT)
  3426. ChangeGC                (SETF (GCONTEXT-JOIN-STYLE GC) KEYWORD)
  3427. ChangeGC                (SETF (GCONTEXT-LINE-STYLE GC) KEYWORD)
  3428. ChangeGC                (SETF (GCONTEXT-LINE-WIDTH GC) CARD16)
  3429. ChangeGC                (SETF (GCONTEXT-PLANE-MASK GC) CARD32)
  3430. ChangeGC                (SETF (GCONTEXT-STIPPLE GC) PIXMAP)
  3431. ChangeGC                (SETF (GCONTEXT-SUBWINDOW-MODE GC) KEYWORD)
  3432. ChangeGC                (SETF (GCONTEXT-TILE GC) PIXMAP)
  3433. ChangeGC                (SETF (GCONTEXT-TS-X GC) INT16)
  3434. ChangeGC                (SETF (GCONTEXT-TS-Y GC) INT16)
  3435. ChangeWindowAttributes  (SETF (WINDOW-BACKGROUND WINDOW) VALUE)
  3436. ChangeWindowAttributes  (SETF (WINDOW-BACKING-PIXEL WINDOW) VALUE)
  3437. ChangeWindowAttributes  (SETF (WINDOW-BACKING-PLANES WINDOW) VALUE)
  3438. ChangeWindowAttributes  (SETF (WINDOW-BACKING-STORE WINDOW) VALUE)
  3439. ChangeWindowAttributes  (SETF (WINDOW-BIT-GRAVITY WINDOW) VALUE)
  3440. ChangeWindowAttributes  (SETF (WINDOW-BORDER WINDOW) VALUE)
  3441. ChangeWindowAttributes  (SETF (WINDOW-COLORMAP WINDOW) VALUE)
  3442. ChangeWindowAttributes  (SETF (WINDOW-CURSOR WINDOW) VALUE)
  3443. ChangeWindowAttributes  (SETF (WINDOW-DO-NOT-PROPAGATE-MASK WINDOW) VALUE)
  3444. ChangeWindowAttributes  (SETF (WINDOW-EVENT-MASK WINDOW) VALUE)
  3445. ChangeWindowAttributes  (SETF (WINDOW-GRAVITY WINDOW) VALUE)
  3446. ChangeWindowAttributes  (SETF (WINDOW-OVERRIDE-REDIRECT WINDOW) VALUE)
  3447. ConfigureWindow         (SETF (WINDOW-PRIORITY WINDOW &OPTIONAL SIBLING) INTEGER)
  3448. ChangeWindowAttributes  (SETF (WINDOW-SAVE-UNDER WINDOW) VALUE)
  3449.  
  3450.  
  3451.  
  3452. ;; Here's a list of the CLX functions that don't directly correspond to 
  3453. ;; X Window System requests.  The've been categorized by function:
  3454.  
  3455.                        ;Display Management
  3456. CLOSE-DISPLAY
  3457. CLOSE-DOWN-MODE
  3458. DISPLAY-AFTER-FUNCTION ;; SETF'able
  3459. DISPLAY-FINISH-OUTPUT
  3460. DISPLAY-FORCE-OUTPUT
  3461. DISPLAY-INVOKE-AFTER-FUNCTION
  3462. OPEN-DISPLAY
  3463. WITH-DISPLAY
  3464. WITH-EVENT-QUEUE
  3465.                        ;Extensions
  3466. DECLARE-EVENT
  3467. DECODE-CORE-ERROR
  3468. DEFAULT-ERROR-HANDLER
  3469. DEFINE-CONDITION
  3470. DEFINE-ERROR
  3471. DEFINE-EXTENSION
  3472. DEFINE-GCONTEXT-ACCESSOR
  3473. EXTENSION-OPCODE
  3474.                        ;Events
  3475. EVENT-CASE
  3476. EVENT-LISTEN
  3477. MAPPING-NOTIFY
  3478. PROCESS-EVENT
  3479. QUEUE-EVENT
  3480.                        ;Image
  3481. COPY-IMAGE
  3482. CREATE-IMAGE
  3483. GET-IMAGE
  3484. IMAGE-BLUE-MASK
  3485. IMAGE-DEPTH
  3486. IMAGE-GREEN-MASK
  3487. IMAGE-HEIGHT
  3488. IMAGE-NAME
  3489. IMAGE-PIXMAP
  3490. IMAGE-PLIST
  3491. IMAGE-RED-MASK
  3492. IMAGE-WIDTH
  3493. IMAGE-X-HOT
  3494. IMAGE-Y-HOT
  3495. PUT-IMAGE
  3496. READ-BITMAP-FILE
  3497. WRITE-BITMAP-FILE
  3498.                        ;Keysyms
  3499. CHARACTER->KEYSYMS
  3500. CHARACTER-IN-MAP-P
  3501. DEFAULT-KEYSYM-INDEX
  3502. DEFAULT-KEYSYM-TRANSLATE
  3503. DEFINE-KEYSYM
  3504. DEFINE-KEYSYM-SET
  3505. KEYCODE->CHARACTER
  3506. KEYCODE->KEYSYM
  3507. KEYSYM
  3508. KEYSYM->CHARACTER
  3509. KEYSYM-IN-MAP-P
  3510. KEYSYM-SET
  3511. UNDEFINE-KEYSYM
  3512.                        ;Properties
  3513. CUT-BUFFER
  3514. GET-STANDARD-COLORMAP
  3515. GET-WM-CLASS
  3516. ICON-SIZES
  3517. MAKE-WM-HINTS
  3518. MAKE-WM-SIZE-HINTS
  3519. ROTATE-CUT-BUFFERS
  3520. SET-STANDARD-COLORMAP
  3521. SET-WM-CLASS
  3522. TRANSIENT-FOR
  3523. WM-CLIENT-MACHINE
  3524. WM-COMMAND
  3525. WM-HINTS
  3526. WM-HINTS-FLAGS
  3527. WM-HINTS-ICON-MASK
  3528. WM-HINTS-ICON-PIXMAP
  3529. WM-HINTS-ICON-WINDOW
  3530. WM-HINTS-ICON-X
  3531. WM-HINTS-ICON-Y
  3532. WM-HINTS-INITIAL-STATE
  3533. WM-HINTS-INPUT
  3534. WM-HINTS-P
  3535. WM-HINTS-WINDOW-GROUP
  3536. WM-ICON-NAME
  3537. WM-NAME
  3538. WM-NORMAL-HINTS
  3539. WM-SIZE-HINTS-HEIGHT
  3540. WM-SIZE-HINTS-HEIGHT-INC
  3541. WM-SIZE-HINTS-MAX-ASPECT
  3542. WM-SIZE-HINTS-MAX-HEIGHT
  3543. WM-SIZE-HINTS-MAX-WIDTH
  3544. WM-SIZE-HINTS-MIN-ASPECT
  3545. WM-SIZE-HINTS-MIN-HEIGHT
  3546. WM-SIZE-HINTS-MIN-WIDTH
  3547. WM-SIZE-HINTS-P
  3548. WM-SIZE-HINTS-USER-SPECIFIED-POSITION-P
  3549. WM-SIZE-HINTS-USER-SPECIFIED-SIZE-P
  3550. WM-SIZE-HINTS-WIDTH
  3551. WM-SIZE-HINTS-WIDTH-INC
  3552. WM-SIZE-HINTS-X
  3553. WM-SIZE-HINTS-Y
  3554. WM-ZOOM-HINTS
  3555.                        ;Misc.
  3556. MAKE-COLOR
  3557. MAKE-EVENT-KEYS
  3558. MAKE-EVENT-MASK
  3559. MAKE-RESOURCE-DATABASE
  3560. MAKE-STATE-KEYS
  3561. MAKE-STATE-MASK
  3562. DISCARD-FONT-INFO
  3563. TRANSLATE-DEFAULT
  3564.                        ;Structures
  3565. BITMAP-FORMAT-LSB-FIRST-P
  3566. BITMAP-FORMAT-P
  3567. BITMAP-FORMAT-PAD
  3568. BITMAP-FORMAT-UNIT
  3569. BITMAP-IMAGE
  3570.  
  3571. COLOR-BLUE
  3572. COLOR-GREEN
  3573. COLOR-P
  3574. COLOR-RED
  3575. COLOR-RGB
  3576. COLORMAP-DISPLAY
  3577. COLORMAP-EQUAL
  3578. COLORMAP-ID
  3579. COLORMAP-P
  3580.  
  3581. CURSOR-DISPLAY
  3582. CURSOR-EQUAL
  3583. CURSOR-ID
  3584. CURSOR-P
  3585.  
  3586. DRAWABLE-DISPLAY
  3587. DRAWABLE-EQUAL
  3588. DRAWABLE-ID
  3589. DRAWABLE-P
  3590.  
  3591. FONT-DISPLAY
  3592. FONT-EQUAL
  3593. FONT-ID
  3594. FONT-MAX-BOUNDS
  3595. FONT-MIN-BOUNDS
  3596. FONT-P
  3597. FONT-PLIST
  3598.  
  3599. GCONTEXT-DISPLAY
  3600. GCONTEXT-EQUAL
  3601. GCONTEXT-ID
  3602. GCONTEXT-P
  3603. GCONTEXT-PLIST
  3604.  
  3605. DISPLAY-AUTHORIZATION-DATA
  3606. DISPLAY-AUTHORIZATION-NAME
  3607. DISPLAY-BITMAP-FORMAT
  3608. DISPLAY-BYTE-ORDER
  3609. DISPLAY-DEFAULT-SCREEN
  3610. DISPLAY-DISPLAY
  3611. DISPLAY-ERROR-HANDLER
  3612. DISPLAY-IMAGE-LSB-FIRST-P
  3613. DISPLAY-KEYCODE-RANGE
  3614. DISPLAY-MAX-KEYCODE
  3615. DISPLAY-MAX-REQUEST-LENGTH
  3616. DISPLAY-MIN-KEYCODE
  3617. DISPLAY-MOTION-BUFFER-SIZE
  3618. DISPLAY-NSCREENS
  3619. DISPLAY-P
  3620. DISPLAY-PIXMAP-FORMATS
  3621. DISPLAY-PLIST
  3622. DISPLAY-PROTOCOL-MAJOR-VERSION
  3623. DISPLAY-PROTOCOL-MINOR-VERSION
  3624. DISPLAY-PROTOCOL-VERSION
  3625. DISPLAY-RELEASE-NUMBER
  3626. DISPLAY-RESOURCE-ID-BASE
  3627. DISPLAY-RESOURCE-ID-MASK
  3628. DISPLAY-ROOTS
  3629. DISPLAY-SQUISH
  3630. DISPLAY-VENDOR
  3631. DISPLAY-VENDOR-NAME
  3632. DISPLAY-VERSION-NUMBER
  3633. DISPLAY-XDEFAULTS
  3634. DISPLAY-XID
  3635.  
  3636. PIXMAP-DISPLAY
  3637. PIXMAP-EQUAL
  3638. PIXMAP-FORMAT-BITS-PER-PIXEL
  3639. PIXMAP-FORMAT-DEPTH
  3640. PIXMAP-FORMAT-P
  3641. PIXMAP-FORMAT-SCANLINE-PAD
  3642. PIXMAP-ID
  3643. PIXMAP-P
  3644. PIXMAP-PLIST
  3645.  
  3646. SCREEN-BACKING-STORES
  3647. SCREEN-BLACK-PIXEL
  3648. SCREEN-DEFAULT-COLORMAP
  3649. SCREEN-DEPTHS
  3650. SCREEN-EVENT-MASK-AT-OPEN
  3651. SCREEN-HEIGHT
  3652. SCREEN-HEIGHT-IN-MILLIMETERS
  3653. SCREEN-MAX-INSTALLED-MAPS
  3654. SCREEN-MIN-INSTALLED-MAPS
  3655. SCREEN-P
  3656. SCREEN-PLIST
  3657. SCREEN-ROOT
  3658. SCREEN-ROOT-DEPTH
  3659. SCREEN-ROOT-VISUAL
  3660. SCREEN-SAVE-UNDERS-P
  3661. SCREEN-WHITE-PIXEL
  3662. SCREEN-WIDTH
  3663. SCREEN-WIDTH-IN-MILLIMETERS
  3664.  
  3665. VISUAL-INFO
  3666. VISUAL-INFO-BITS-PER-RGB
  3667. VISUAL-INFO-BLUE-MASK
  3668. VISUAL-INFO-CLASS
  3669. VISUAL-INFO-COLORMAP-ENTRIES
  3670. VISUAL-INFO-GREEN-MASK
  3671. VISUAL-INFO-ID
  3672. VISUAL-INFO-P
  3673. VISUAL-INFO-PLIST
  3674. VISUAL-INFO-RED-MASK
  3675.  
  3676. WINDOW-DISPLAY
  3677. WINDOW-EQUAL
  3678. WINDOW-ID
  3679. WINDOW-P
  3680. WINDOW-PLIST
  3681.